FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Displaying an array value in two columns
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Displaying an array value in two columns [message #185852 is a reply to message #185849] Mon, 12 May 2014 20:00 Go to previous message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma:
Senior Member
On 12/05/14 21:15, Dan Jacobs wrote:
> Hello all.
>
> I am fairly new to PHP and have an interesting question concerning the
> proper way to pass an array value from one division to another.
> I have an array I am building "on the fly" so to say. Let's say it has
> 100 items in it. Inititally, there is only one dimension to the array.
> Then later, I add a second dimension to that mainly to save time from
> having to create a second array.
> As an example, I have created $myarray[0]. On the second dimension I add
> $myarray[0]['name'].
> Here comes the problem. $myarray[0] prints and displays just fine in
> column 1 and column 2. $myarray[0]['name'] prints fine in column 1, but
> when printed in column 2, I get an illegal offset error message. Is
> there something I am missing to get $myarray[0]['name'] to print in
> column 2?

As Ben already explained, we need the code to be able to help you.
Could it be that you think your array is multidimensional but it ain't
in the all cases.


You can try to use var_export() to see how the array looks like

syslog(LOG_INFO, var_export($myarray, true));

then look in the /var/log/messages (or where your system logs syslog
messages) to see how the array looked like.


You could also use a function like this (far from perfect) to display
the array:

function printArray($yourArray) {
foreach($yourArray as $value) {
if(is_array($value)) {
print "\n";
printArray($value);
} else {
print $value ." | ";
}
}
print "\n";
}


example:
$myarray = array( "something",
"something else",
array("name" => "Someone", "Age" => "50"),
array("name" => "Zimone", "Age" => "12", "Color" => "Blue")
);
printArray($myarray);

output something like:
something | something else |
Someone | 50 |

Zimone | 12 | Blue |

--

//Aho
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: richard
Next Topic: Playlist different from displayed list in source html code
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 29 21:22:07 GMT 2024

Total time taken to generate the page: 0.03949 seconds