davemere Posted October 12, 2008 Share Posted October 12, 2008 Hi there I'm building anl app where I'm passing a number of different variables to my pages. The one I'm interested in right now is an array, which itself contains what I think is another array. I need to split out one particular field so I can change the way it is processed by the front end. Problem is that I've been unable to find the syntax to help me do this! ??? I've found a function that lets me display what the variables looks like: array(1) { [0]=> array(3) { ["value"]=> string(14) "string content" } } I need to extract the string "string content". I think what I'm looking at here is an array of an array. Could anyone suggest what code I can use to split out this string? I'm very new to php, so please excuse this basic question! Quote Link to comment https://forums.phpfreaks.com/topic/128111-splitting-array-in-array/ Share on other sites More sharing options...
DarkWater Posted October 12, 2008 Share Posted October 12, 2008 $array[0]['value'] would contain "string content" if $array is your main array. Quote Link to comment https://forums.phpfreaks.com/topic/128111-splitting-array-in-array/#findComment-663458 Share on other sites More sharing options...
Stooney Posted October 12, 2008 Share Posted October 12, 2008 It's just a multidimensional array. In your case: <?php $array1=array('array2'=>array('content'=>'string content')); $string=$array1['array2']['content']; echo $string; //Will out put 'string content'; Also, to view the structure of an array just use print_r($array); Quote Link to comment https://forums.phpfreaks.com/topic/128111-splitting-array-in-array/#findComment-663460 Share on other sites More sharing options...
davemere Posted October 12, 2008 Author Share Posted October 12, 2008 Thanks both of you, I know that was an easy one, but was having problems there...Sunday evenings... print_r($array); is really useful as well. I put applied it to the main content variable and it's showing everything that is returned. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/128111-splitting-array-in-array/#findComment-663468 Share on other sites More sharing options...
DarkWater Posted October 12, 2008 Share Posted October 12, 2008 Just to let you know, you can use print_r() like this to make it even more readable: <?php $array = array('something' => array('complex', 'really complex', 'complex' => 'times 2')); echo '<pre>' . print_r($array, true) . '</pre>'; ?> Using it in <pre> tags preserves the spacing. Quote Link to comment https://forums.phpfreaks.com/topic/128111-splitting-array-in-array/#findComment-663469 Share on other sites More sharing options...
keeB Posted October 14, 2008 Share Posted October 14, 2008 PHP CLI Also preserves the spacing without <pre> tags, which is why it's not there by default Quote Link to comment https://forums.phpfreaks.com/topic/128111-splitting-array-in-array/#findComment-665459 Share on other sites More sharing options...
DarkWater Posted October 14, 2008 Share Posted October 14, 2008 Quote PHP CLI Also preserves the spacing without <pre> tags, which is why it's not there by default Only because it's used on the command line and \n actually means something to the shell (means nothing to the web browser, just formats source code...). I use the CLI all the time (hell, I think I use it more than the CGI sometimes) to test scripts and little pieces of code. I open up like emacs and write some code, save it to a temp. file (just easier) and run it in the CLI. Quote Link to comment https://forums.phpfreaks.com/topic/128111-splitting-array-in-array/#findComment-665484 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.