unemployment Posted March 9, 2011 Share Posted March 9, 2011 How can I select a value in an array but not its key. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 9, 2011 Share Posted March 9, 2011 Huh? Quote Link to comment Share on other sites More sharing options...
phpfreaks2280 Posted March 9, 2011 Share Posted March 9, 2011 you can use in_array function of php, and pass first param as array value and second as array as per that you can search first params in your array. Quote Link to comment Share on other sites More sharing options...
unemployment Posted March 9, 2011 Author Share Posted March 9, 2011 Right now I have... Look at the commented out code for more details foreach ($results as $result) { $page = $result['page']; $total = $result['SUM(`like`)']; $extremoved = substr($page, 0, -4); foreach ($pages as $name) { if (ucwords($extremoved) == $name) // I need $name to equal the value of the array... $name = 'about' NOT ITS KEY => 'About', { ?> <div class="mhl mvs"> <span class="left"><?php echo ucwords($extremoved); ?></span> // I need this to echo out the $names KEY rather than $extremoved <span class="f_right">(<?php echo $total; ?>)</span> </div> <?php } } } $pages = array( 'about' => 'About', 'accountSettings' => 'Account Settings', ); Quote Link to comment Share on other sites More sharing options...
jcbones Posted March 9, 2011 Share Posted March 9, 2011 foreach ($results as $result) { $page = $result['page']; $total = $result['SUM(`like`)']; $extremoved = substr($page, 0, -4); foreach ($pages as $key => $value) //slight change to the foreach, this will grab the key and the value. { if (ucwords($extremoved) == $value) // I need $name to equal the value of the array... $name = 'about' NOT ITS KEY => 'About', According to your block below, 'About' is the value and not the key. { ?> <div class="mhl mvs"> <span class="left"><?php echo ucwords($key); ?></span> // I need this to echo out the $names KEY rather than $extremoved <span class="f_right">(<?php echo $total; ?>)</span> </div> <?php } } } $pages = array( 'KEY' => 'VALUE', 'about' => 'About', 'accountSettings' => 'Account Settings', ); Quote Link to comment Share on other sites More sharing options...
unemployment Posted March 9, 2011 Author Share Posted March 9, 2011 Thank you soooo much. That solves my issue and taught me a few things a long the way. Quote Link to comment Share on other sites More sharing options...
jcbones Posted March 9, 2011 Share Posted March 9, 2011 You're welcome! Glad I finally explained something clearly. Quote Link to comment Share on other sites More sharing options...
unemployment Posted March 9, 2011 Author Share Posted March 9, 2011 Ha, so clear that I've already got another function working.. wahoo Quote Link to comment 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.