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? 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? 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. 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]; } ?> 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. 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? 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. 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]; 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! Link to comment https://forums.phpfreaks.com/topic/86249-solved-new-array-question/#findComment-440597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.