ballhogjoni Posted January 16, 2008 Share Posted January 16, 2008 MY array has like 71 indexes. How do I pick and choose which index to echo in the browser? Quote Link to comment https://forums.phpfreaks.com/topic/86249-solved-new-array-question/ Share on other sites More sharing options...
interpim Posted January 16, 2008 Share Posted January 16, 2008 many ways... how is your array laid out and what do you want to see? Quote Link to comment https://forums.phpfreaks.com/topic/86249-solved-new-array-question/#findComment-440551 Share on other sites More sharing options...
ballhogjoni Posted January 16, 2008 Author Share Posted January 16, 2008 My original array looks like this: array([0] => 1|test|test1|etc...) So I need some code to seperate the the value by the | mark. That what this code does: <?php $test = array($resp); $new_array = array(); foreach ($test as $key => $val) { $new_array[$key] = explode('|',$val); } echo '<pre>' . print_r($new_array,true) . '</pre>'; // debug ?> Now I want to echo (print into the browser) the value of index 2 only, not the entire array. Quote Link to comment https://forums.phpfreaks.com/topic/86249-solved-new-array-question/#findComment-440559 Share on other sites More sharing options...
trq Posted January 16, 2008 Share Posted January 16, 2008 <?php $test = array($resp); $new_array = array(); foreach ($test as $key => $val) { $new_array[$key] = explode('|',$val); echo $new_array[2]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86249-solved-new-array-question/#findComment-440560 Share on other sites More sharing options...
ballhogjoni Posted January 16, 2008 Author Share Posted January 16, 2008 Thorpe, it dint seem to work. My output was nothing. Quote Link to comment https://forums.phpfreaks.com/topic/86249-solved-new-array-question/#findComment-440573 Share on other sites More sharing options...
trq Posted January 16, 2008 Share Posted January 16, 2008 Actually, a closer look reveals it is mutidimensional. What does.... <?php $test = array($resp); $new_array = array(); foreach ($test as $key => $val) { $new_array[$key] = explode('|',$val); } echo "<pre>"; print_r($new_array,true); echo "</pre>"; ?> produce? And which part do you want? Quote Link to comment https://forums.phpfreaks.com/topic/86249-solved-new-array-question/#findComment-440576 Share on other sites More sharing options...
ballhogjoni Posted January 16, 2008 Author Share Posted January 16, 2008 <?php Array ( [0] => Array ( [0] => 3 [1] => 1 [2] => 6 [3] => (TESTMODE) The credit card number is invalid. [4] => 000000 [5] => P [6] => 0 etc...to the 72nd index of this array ) ) ?> I want to be able to print the value of whatever index I want. I.E. this index and value pair [3] => (TESTMODE) The credit card number is invalid. should just show the value part in a browser not the actual index. Also I don't want to print all the values of all the indexes. Example code that I think should work but doesn't is: echo $new_array[3]; //output should be: (TESTMODE) The credit card number is invalid. Quote Link to comment https://forums.phpfreaks.com/topic/86249-solved-new-array-question/#findComment-440591 Share on other sites More sharing options...
trq Posted January 16, 2008 Share Posted January 16, 2008 As per your example it would be.... echo $new_array[0][3]; Quote Link to comment https://forums.phpfreaks.com/topic/86249-solved-new-array-question/#findComment-440595 Share on other sites More sharing options...
ballhogjoni Posted January 16, 2008 Author Share Posted January 16, 2008 Thanks Thorpe! Quote Link to comment https://forums.phpfreaks.com/topic/86249-solved-new-array-question/#findComment-440597 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.