Page 1 of 1

Need Help Printing Multidimensional Array Element

Posted: Mon Feb 23, 2009 1:15 pm
by sodonnell
Hi,

I am very new to PHP and am trying to do something that is probably pretty simple to most PHP programmers but I am finding the syntax to be difficult.

I have a multidemensional array and I want to be able to print one or more data values from that array, but so far I just get blanks back on the print (and I know there is data being returned in this array).

Can someone please help me with the syntax for this?

This is the array structure and as you can see, it contains two multidimenstional arrays:

Code: Select all

 $out_parameters = array( 
                          "IOERRFLG"                          =>"IOERRFLG",
                          "IOERRDESC"                         =>"IOERRDESC",

                          "OUTARRAY1" =>Array("IPATH"    =>  "IPATH",
                                                 "IPATH2"      =>  "IPATH2",
                                                 "INAME"      =>  "INAME"), 

                          "OUTARRAY2" =>Array("XCNAME"      => "XCNAME",
                                                         "XDNAME"      => "XDNAME",
				     "XDADDRESS"   => "XDADDRESS",
				      "XDLICSTATE"  => "XDLICSTATE")
                        				  );  
This is the syntax I am using to try to print one element from OUTARRAY2 but it does not work.


print $out_parameters($OUTARRAY2['$XCNAME'][1]);


Help! :-)

Re: Need Help Printing Multidimensional Array Element

Posted: Mon Feb 23, 2009 1:16 pm
by Benjamin
Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]

Re: Need Help Printing Multidimensional Array Element

Posted: Mon Feb 23, 2009 1:20 pm
by Randwulf
Try this:

print $out_parameters['OUTARRAY2']['XCNAME'];

Re: Need Help Printing Multidimensional Array Element

Posted: Mon Feb 23, 2009 5:05 pm
by sodonnell
That didn't work either.

Well...I guess I'll keep playing with it until I figure it out.

I know it's not black magic... :-) ...I just have to get familiar enough with PHP to understand how to do it I guess.

Thanks for the suggestion!

Re: Need Help Printing Multidimensional Array Element

Posted: Mon Feb 23, 2009 5:45 pm
by semlar

Code: Select all

<pre>
<?php
$out_parameters = array(
    "IOERRFLG" => "IOERRFLG",
    "IOERRDESC" => "IOERRDESC",
 
    "OUTARRAY1" => array(
        "IPATH" => "IPATH",
        "IPATH2" => "IPATH2",
        "INAME" => "INAME"
    ),
 
    "OUTARRAY2" => array(
        "XCNAME" => "XCNAME",
        "XDNAME" => "XDNAME",
        "XDADDRESS" => "XDADDRESS",
        "XDLICSTATE" => "XDLICSTATE"
    )
);
 
print_r($out_parameters);
 
print_r($out_parameters['OUTARRAY2']);
 
echo $out_parameters['OUTARRAY2']['XCNAME'];
?>
</pre>
I'm not sure why you're using the same thing for the keys and the values. Depending on what the array is for, it should probably be done differently.