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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.