For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > January 2006 > Arrayed confusion









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Arrayed confusion
barret bonden

2006-01-10, 7:01 pm

having trouble with array of this design
$directory_tree[] = array(
'path' => "test path",
'name' => "test name");

all my efforts at getting at the data don't work ...

//print( $directory_tree["path"]) ;
//print( $directory_tree[0]) ;
print( $directory_tree['path'][0]) ;


Zilla

2006-01-10, 7:01 pm

barret bonden wrote:
> having trouble with array of this design
> $directory_tree[] = array(
> 'path' => "test path",
> 'name' => "test name");
>
> all my efforts at getting at the data don't work ...
>
> //print( $directory_tree["path"]) ;
> //print( $directory_tree[0]) ;
> print( $directory_tree['path'][0]) ;
>
>


Try:

print($directory_tree[0]['path']);

Zilla.
Zilla

2006-01-10, 7:01 pm

barret bonden wrote:
> having trouble with array of this design
> $directory_tree[] = array(
> 'path' => "test path",
> 'name' => "test name");
>
> all my efforts at getting at the data don't work ...
>
> //print( $directory_tree["path"]) ;
> //print( $directory_tree[0]) ;
> print( $directory_tree['path'][0]) ;
>
>


Try:

print($directory_tree[0]['path']);

Zilla.
Janwillem Borleffs

2006-01-10, 7:01 pm

barret bonden wrote:
> having trouble with array of this design
> $directory_tree[] = array(
> 'path' => "test path",
> 'name' => "test name");
>
> all my efforts at getting at the data don't work ...
>
> //print( $directory_tree["path"]) ;
> //print( $directory_tree[0]) ;
> print( $directory_tree['path'][0]) ;
>


Assuming $directory_tree has only one element, which is an associative array
containg a 'path' key, you would do:

print $directory_tree[0]['path'];

See http://www.php.net/manual/ and http://www.php.net/array for more info.


JW


Zilla

2006-01-10, 7:01 pm

Sorry for the double post... Won't happen again.

Zilla.
John Murtari

2006-01-10, 7:01 pm

"barret bonden" <arthur@networks-cc.com> writes:

> having trouble with array of this design
> $directory_tree[] = array(
> 'path' => "test path",
> 'name' => "test name");
>
> all my efforts at getting at the data don't work ...
>
> //print( $directory_tree["path"]) ;
> //print( $directory_tree[0]) ;
> print( $directory_tree['path'][0]) ;
>
>


Okay, your big problem was the [] in
the variable name, the following works fine.
The second print gets you the first character.

$directory_tree = array(
'path' => "test path",
'name' => "test name");


print( $directory_tree["path"]."\n") ;
print( $directory_tree['path'][0]."\n") ;

--
John
________________________________________
___________________________
John Murtari Software Workshop Inc.
jmurtari@following domain 315.635-1968(x-211) "TheBook.Com" (TM)
http://thebook.com/
barret bonden

2006-01-10, 7:01 pm

Got it. Thank you all.

( Makes sense. What a joy of a language ~ ASP and VB.NET have been driving
me nuts)


"Zilla" <mail.is.not@an.option> wrote in message
news:43C42721.9070009@an.option...
> barret bonden wrote:
>
> Try:
>
> print($directory_tree[0]['path']);
>
> Zilla.



Jim Michaels

2006-01-17, 3:55 am

maybe what you were tryiong to do was
$directory_tree = array(
'path' => "test path",
'name' => "test name");

instead. then you don't need the [0].
[] adds a new array index at <count++> for the newly assigned item. if the
variable didn't exist before, it starts with [0] and increments count after
that.
with the above assignment, you can add all the new items you want by just
assigning them. $directory_tree['fuzz']="blah";

"barret bonden" <arthur@networks-cc.com> wrote in message
news:EhXwf.81$h_.20@fe11.lga...
> Got it. Thank you all.
>
> ( Makes sense. What a joy of a language ~ ASP and VB.NET have been
> driving
> me nuts)
>
>
> "Zilla" <mail.is.not@an.option> wrote in message
> news:43C42721.9070009@an.option...
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com