Need Help Printing Multidimensional Array Element

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sodonnell
Forum Newbie
Posts: 2
Joined: Mon Feb 23, 2009 1:07 pm

Need Help Printing Multidimensional Array Element

Post 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! :-)
Last edited by sodonnell on Mon Feb 23, 2009 1:19 pm, edited 2 times in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Need Help Printing Multidimensional Array Element

Post 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]
Randwulf
Forum Commoner
Posts: 63
Joined: Wed Jan 07, 2009 7:07 am

Re: Need Help Printing Multidimensional Array Element

Post by Randwulf »

Try this:

print $out_parameters['OUTARRAY2']['XCNAME'];
sodonnell
Forum Newbie
Posts: 2
Joined: Mon Feb 23, 2009 1:07 pm

Re: Need Help Printing Multidimensional Array Element

Post 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!
semlar
Forum Commoner
Posts: 61
Joined: Fri Feb 20, 2009 10:45 pm

Re: Need Help Printing Multidimensional Array Element

Post 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.
Post Reply