Jump to content

Select an array, but not its key


unemployment

Recommended Posts

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',
);

Link to comment
Share on other sites

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',
);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.