Forum Moderators: coopster

Message Too Old, No Replies

Sending array to function problem

         

smagdy

8:17 am on Aug 3, 2018 (gmt 0)

10+ Year Member



Hi,


echo $events; //THIS ECHOS THE ARRAY TO SCREEN

$events = [$events]; // HERE the variable has the correct array info, but it only works if i Copy and Paste the array from screen to $events variable

echo build_html_calendar($_GET['y'], $_GET['d'], $events);


The array has info like this and it works if i replace the second line to this

$events = ['2018-07-01'=> ['text'=> "
",'href' => "#C13757"],'2018-07-02'=> ['text'=> "08:09:56
16:05:00",'href' => ""],'2018-07-03'=> ['text'=> "08:13:21
16:04:52",'href' => ""],'2018-07-04'=> ['text'=> "08:09:06
16:05:34",'href' => ""],'2018-07-05'=> ['text'=> "08:10:22
16:07:56",'href' => ""],'2018-07-06'=> ['text'=> "08:08:49
15:56:35",'href' => ""],'2018-07-07'=> ['text'=> "
",'href' => "#C13757"],'2018-07-08'=> ['text'=> "
",'href' => "#C13757"],'2018-07-09'=> ['text'=> "08:16:21
16:03:10",'href' => ""],'2018-07-10'=> ['text'=> "08:03:25
16:07:58",'href' => ""],'2018-07-11'=> ['text'=> "08:06:46
11:37:30",'href' => ""],'2018-07-12'=> ['text'=> "08:02:38
09:30:23",'href' => ""],'2018-07-13'=> ['text'=> "08:07:21
16:01:51",'href' => ""],'2018-07-14'=> ['text'=> "
",'href' => "#C13757"],'2018-07-15'=> ['text'=> "
",'href' => "#C13757"],'2018-07-16'=> ['text'=> "08:22:02
11:24:37",'href' => ""],'2018-07-17'=> ['text'=> "08:12:35
16:01:42",'href' => ""],'2018-07-18'=> ['text'=> "
",'href' => "#C13757"],'2018-07-19'=> ['text'=> "
",'href' => "#C13757"],'2018-07-20'=> ['text'=> "08:13:26
16:00:05",'href' => ""],'2018-07-21'=> ['text'=> "
",'href' => "#C13757"],'2018-07-22'=> ['text'=> "
",'href' => "#C13757"],'2018-07-23'=> ['text'=> "
",'href' => "#C13757"],'2018-07-24'=> ['text'=> "
",'href' => "#C13757"],'2018-07-25'=> ['text'=> "
",'href' => "#C13757"],'2018-07-26'=> ['text'=> "
",'href' => "#C13757"],'2018-07-27'=> ['text'=> "
",'href' => "#C13757"],'2018-07-28'=> ['text'=> "
",'href' => "#C13757"],'2018-07-29'=> ['text'=> "
",'href' => "#C13757"],'2018-07-30'=> ['text'=> "08:07:20
16:02:57",'href' => ""],'2018-07-31'=> ['text'=> "08:02:42
16:03:12",'href' => ""]]


So what is missing in the variable to make it read the array correctly?

Thanks in adance!

smagdy

10:03 am on Aug 3, 2018 (gmt 0)

10+ Year Member



I fixed it.

Thanks

Dimitri

10:52 am on Aug 4, 2018 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



May be you can explain what was not working, and what you did to fix it, ... it can help someone else facing the same situation.

Matthew1980

7:46 am on Sep 24, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Guys,

Been a while since I posted - but just thought I would point out that passing the likes of _GET _POST _COOKIE into functions isn't required because they're 'super-globals'. If they're set:
(!ISSET($_GET['y']) || !ISSET($_GET['d']))


then you can access them anywhere in the context of the script - so no need to pass. This just makes the code tidier and easier to read.

Ok, it's before coffe - but this just doesn't make sense.

$events = [$events]; // HERE the variable has the correct array info, but it only works if i Copy and Paste the array from screen to $events variable


If you're echoing the array to screen at that point then you're set - doing $events = [$events]; with the array operand enclosing the variable will confuse matters; what are you trying to achieve with this assignment? To me it looks like you're trying to create a snapshot of this variable for use elsewhere...

Happy coding!
Cheers,
MRb
(And yes, please post the sollution so that other people benefit - that's the point of the forums!)