Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #13615

Re: Displaying an array value in two columns

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From "J.O. Aho" <user@example.net>
Newsgroups comp.lang.php
Subject Re: Displaying an array value in two columns
Date Mon, 12 May 2014 22:00:34 +0200
Lines 64
Message-ID <btcnj2FcvfeU1@mid.individual.net> (permalink)
References <Qq-dnTmQ3KWtg-zOnZ2dnUVZ_oidnZ2d@giganews.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net f/HDa+E9cESNTJ7SbGCIrQfG6Qzf9Cx9Ut+5r5zuRTVPgHbGb+
Cancel-Lock sha1:KiUg4S7D3FVSyWKZOvy6rF49NUA=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
In-Reply-To <Qq-dnTmQ3KWtg-zOnZ2dnUVZ_oidnZ2d@giganews.com>
Xref csiph.com comp.lang.php:13615

Show key headers only | View raw


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

Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Displaying  an array value in two columns "Dan Jacobs" <Dan.Jacobs@gmal.com> - 2014-05-12 15:15 -0400
  Re: Displaying  an array value in two columns Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-05-12 20:27 +0100
  Re: Displaying  an array value in two columns Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-12 21:49 +0200
  Re: Displaying  an array value in two columns "J.O. Aho" <user@example.net> - 2014-05-12 22:00 +0200

csiph-web