如何将三个值放入一个数组php并将其放入每个数组?
我想把三个值放到一个数组中,而不是两个。就像下面的代码一样,我怎样才能实现呢如何将三个值放入一个数组php并将其放入每个数组?,php,arrays,Php,Arrays,我想把三个值放到一个数组中,而不是两个。就像下面的代码一样,我怎样才能实现呢 $emo\u word=array( “LOL!”=>“LOL”=>1, “酷!”=>“酷”=>2, “可爱!”=>“可爱”=>3, “爱它!”=>“爱它”=>4 ); foreach($first=>$second=>$third) { //代码在这里 } 此处的语法错误: $emo_word = array( "LOL !" => 'lol' => 1, //---------------
$emo\u word=array(
“LOL!”=>“LOL”=>1,
“酷!”=>“酷”=>2,
“可爱!”=>“可爱”=>3,
“爱它!”=>“爱它”=>4
);
foreach($first=>$second=>$third)
{
//代码在这里
}
此处的语法错误:
$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
}
您可能需要改用数组。它应该是这样的吗
$emo_word = array(
1 => array("LOL !", 'lol')
2 => array("COOL !", 'cool'),
3 => array("CUTE !", 'cute'),
4 => array("LOVE IT !", 'love_it')
);
这取决于你到底想做什么。如果你觉得这是笑代码>和其他是标识符,将它们作为索引保留。此处的语法错误:
$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
}
您可能需要改用数组。它应该是这样的吗
$emo_word = array(
1 => array("LOL !", 'lol')
2 => array("COOL !", 'cool'),
3 => array("CUTE !", 'cute'),
4 => array("LOVE IT !", 'love_it')
);
这取决于你到底想做什么。如果你觉得这是笑代码>和其他是标识符,将它们作为索引保留。此处的语法错误:
$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
}
您可能需要改用数组。它应该是这样的吗
$emo_word = array(
1 => array("LOL !", 'lol')
2 => array("COOL !", 'cool'),
3 => array("CUTE !", 'cute'),
4 => array("LOVE IT !", 'love_it')
);
这取决于你到底想做什么。如果你觉得这是笑代码>和其他是标识符,将它们作为索引保留。此处的语法错误:
$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
}
您可能需要改用数组。它应该是这样的吗
$emo_word = array(
1 => array("LOL !", 'lol')
2 => array("COOL !", 'cool'),
3 => array("CUTE !", 'cute'),
4 => array("LOVE IT !", 'love_it')
);
这取决于你到底想做什么。如果你觉得这是笑和其他是标识符,将它们作为索引保留。如果您想保持它原来的样子,您可以这样做
$emo_word = array(
"LOL !" => array('lol' => 1),
"COOL !" => array('cool'=> 2,),
"CUTE !" => array('cute' =>3),
"LOVE IT !" => array('love_it'=>4)
);
访问LOL!然后得到1,你会这样做:
$emo_word['LOL !']['lol']
如果你想保持原来的样子,你会这样做的
$emo_word = array(
"LOL !" => array('lol' => 1),
"COOL !" => array('cool'=> 2,),
"CUTE !" => array('cute' =>3),
"LOVE IT !" => array('love_it'=>4)
);
访问LOL!然后得到1,你会这样做:
$emo_word['LOL !']['lol']
如果你想保持原来的样子,你会这样做的
$emo_word = array(
"LOL !" => array('lol' => 1),
"COOL !" => array('cool'=> 2,),
"CUTE !" => array('cute' =>3),
"LOVE IT !" => array('love_it'=>4)
);
访问LOL!然后得到1,你会这样做:
$emo_word['LOL !']['lol']
如果你想保持原来的样子,你会这样做的
$emo_word = array(
"LOL !" => array('lol' => 1),
"COOL !" => array('cool'=> 2,),
"CUTE !" => array('cute' =>3),
"LOVE IT !" => array('love_it'=>4)
);
访问LOL!然后得到1,你会这样做:
$emo_word['LOL !']['lol']
我认为您可以使用list命令:
$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;
}
虽然我没有测试它,但这应该是一条路要走。
希望这有帮助
我想您可以使用list命令:
$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;
}
虽然我没有测试它,但这应该是一条路要走。
希望这有帮助
我想您可以使用list命令:
$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;
}
虽然我没有测试它,但这应该是一条路要走。
希望这有帮助
我想您可以使用list命令:
$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;
}
虽然我没有测试它,但这应该是一条路要走。
希望这有帮助
这不是JavaScript!!!你不能做第一件事,所以你也不能做你想做的每件事。解释一下你的目标是什么,你在循环中想做什么?你可以使用列表:这不是JavaScript!!!你不能做第一件事,所以你也不能做你想做的每件事。解释一下你的目标是什么,你在循环中想做什么?你可以使用列表:这不是JavaScript!!!你不能做第一件事,所以你也不能做你想做的每件事。解释一下你的目标是什么,你在循环中想做什么?你可以使用列表:这不是JavaScript!!!你不能做第一件事,所以你也不能做你想做的每件事。解释一下你的目标是什么?在循环中你想做什么?你可以使用列表:如果你决定在LOL中使用关联数组,php文档非常好!还有一些作为标识符,我想在每个单词上加一个ID,这就是为什么我要加1,2,3,4。我能用你建议的代码得到数字1,2,3,4吗?谢谢,我怎样才能进入foreach循环?你能提供一个例子吗?@conan你可以看一看:如果你决定在LOL中使用关联数组,php文档是相当不错的!还有一些作为标识符,我想在每个单词上加一个ID,这就是为什么我要加1,2,3,4。我能用你建议的代码得到数字1,2,3,4吗?谢谢,我怎样才能进入foreach循环?你能提供一个例子吗?@conan你可以看一看:如果你决定在LOL中使用关联数组,php文档是相当不错的!还有一些作为标识符,我想在每个单词上加一个ID,这就是为什么我要加1,2,3,4。我能用你建议的代码得到数字1,2,3,4吗?谢谢,我怎样才能进入foreach循环?你能提供一个例子吗?@conan你可以看一看:如果你决定在LOL中使用关联数组,php文档是相当不错的!还有一些作为标识符,我想在每个单词上加一个ID,这就是为什么我要加1,2,3,4。我能用你建议的代码得到数字1,2,3,4吗?谢谢,我怎样才能进入foreach循环?你能举个例子吗?@conan你可以看看:如果我想得到‘LOL!’在您提供的代码中,您可以执行类似于foreach的foreach($emo\u word as$key=>$value),然后$key将包含所有的键值,如“LOL!”如果我想得到‘LOL!’在您提供的代码中,您可以执行类似于foreach的foreach($emo\u word as$key=>$value),然后$key将包含所有的键值,如“LOL!”如果我想得到‘LOL!’在您提供的代码中,您可以执行类似于foreach的foreach($emo\u word as$key=>$value),然后$key将包含所有的键值,如“LOL!”如果我想得到‘LOL!’在您提供的代码中,您可以执行类似于foreach的foreach($emo\u word as$key=>$value),然后$key将包含所有的键值,如“LOL!”