I want to put three value into one array instead of two. Like below code, how can I achieve that?
$emo_word = array(
"LOL !" => 'lol' => 1,
"COOL !" => 'cool'=> 2,
"CUTE !" => 'cute' =>3,
"LOVE IT !" => 'love_it'=>4
);
foreach( $emo_word as $first=> $second => $third)
{
//code here
}
The syntax is wrong here:
$emo_word = array(
"LOL !" => 'lol' => 1,
//---------------^
"COOL !" => 'cool'=> 2,
"CUTE !" => 'cute' =>3,
"LOVE IT !" => 'love_it'=>4
);
foreach( $emo_word as $first=> $second => $third)
//-------------------------------------^
{
//code here
}
You may need to use an array instead. And it should look like this?
$emo_word = array(
1 => array("LOL !", 'lol')
2 => array("COOL !", 'cool'),
3 => array("CUTE !", 'cute'),
4 => array("LOVE IT !", 'love_it')
);
This depends on what you are exactly wishing to do. If you feel that thos LOL !
and others are the identifiers, keep them as indices.
If you wanted to keep it like you had it you would do it like this
$emo_word = array(
"LOL !" => array('lol' => 1),
"COOL !" => array('cool'=> 2,),
"CUTE !" => array('cute' =>3),
"LOVE IT !" => array('love_it'=>4)
);
to access LOL ! and get the 1 you would go like this:
$emo_word['LOL !']['lol']
I think you can use the list-command:
$emo_world= array(
array("LOL !", "lol", 1),
array("COOL !", "cool", 2),
array("CUTE !", "cute", 3),
);
foreach($emo_world as $world){
list($first, $second, $third) = $world;
echo "Here you go: ".$first." and ".$second." and ".$third;
}
I did not test it though, but this should be the way to go. Hope this helps.