Jump to content

[SOLVED] need help on foreach


pixeltrace

Recommended Posts

hi,

 

i have a code here

$employeeAges;
$employeeAges["Lisa"] = "28";
$employeeAges["Jack"] = "16";
$employeeAges["Ryan"] = "35";
$employeeAges["Rachel"] = "46";
$employeeAges["Grace"] = "34";

foreach( $employeeAges as $key => $value){
echo "Name: $key, Age: $value <br />";
}

 

is there a way where in my foreach function i can omit 1 value of $employeeAges?

example in my echo output i just wanted to have this

Name: Jack, Age: 16
Name: Ryan, Age: 35
Name: Rachel, Age: 46
Name: Grace, Age: 34 

 

is this possible? if not hope you could help me find other methods.

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/72811-solved-need-help-on-foreach/
Share on other sites

<?php

$employeeAges = array();
$employeeAges["Lisa"] = "28";
$employeeAges["Jack"] = "16";
$employeeAges["Ryan"] = "35";
$employeeAges["Rachel"] = "46";
$employeeAges["Grace"] = "34";

foreach( $employeeAges as $key => $value) {
  if ($key != 'Lisa') {
    echo "Name: $key, Age: $value <br />";
  }
}

?>

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.