abrew Posted August 2, 2012 Share Posted August 2, 2012 hi again the beginers asking some help here ,,, when i echo '<pre>'.print_r($results, 1).'</pre>'; it is look like this Array ( 0 => array ( [id]=>101 [year]=>2011 [month]=>11 [in]=>25 ) 2 => array ( [id]=>105 [year]=>2011 [month]=>12 [in]=>3 ) ,,, ) how to pick and show the value '25' only [in] => 25 any sugestion please ,,, ?? Quote Link to comment https://forums.phpfreaks.com/topic/266621-how-to-display-some-values-of-an-array/ Share on other sites More sharing options...
Mahngiel Posted August 2, 2012 Share Posted August 2, 2012 you want to show the value of the entire array set that contains the key pair [in] => 25 ? <?php foreach( $arrays as $array ) { if( in_array('25', $array) ) { print_r( $array ); } } Quote Link to comment https://forums.phpfreaks.com/topic/266621-how-to-display-some-values-of-an-array/#findComment-1366484 Share on other sites More sharing options...
jcbones Posted August 2, 2012 Share Posted August 2, 2012 echo $results[0]['in']; Will give you 25 Quote Link to comment https://forums.phpfreaks.com/topic/266621-how-to-display-some-values-of-an-array/#findComment-1366485 Share on other sites More sharing options...
abrew Posted August 2, 2012 Author Share Posted August 2, 2012 wow wow ,,, as i said i'm beginer ,,, thanx a lot for help ,,, jcbones & mahngiel ,,, thx Quote Link to comment https://forums.phpfreaks.com/topic/266621-how-to-display-some-values-of-an-array/#findComment-1366487 Share on other sites More sharing options...
Drummin Posted August 2, 2012 Share Posted August 2, 2012 This will work as well. <?php $results = Array ( 0 => array ( 'id'=>101, 'year'=>2011, 'month'=>11, 'in'=>25 ), 2 => array ( 'id'=>105, 'year'=>2011, 'month'=>12, 'in'=>3 ) ); echo "<pre>"; print_r($results); echo "</pre>"; $search_in=25; foreach($results as $k1 => $a1){ if ($results[$k1]['in']==$search_in){ //Display each item in this array for $search_in key echo "ID = {$results[$k1]['id']}<br />"; echo "Year = {$results[$k1]['year']}<br />"; echo "Month = {$results[$k1]['month']}<br />"; echo "IN = {$results[$k1]['in']}<br />"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/266621-how-to-display-some-values-of-an-array/#findComment-1366489 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.