我正在学习PHP,对于数组有些困惑。我正在尝试将两个数组合并在一起,但是要将它们的数据结合在一起,就像这样。
数组$instruction1包含食谱说明的名称。
[0] = Prep
[1] = Cook
[2] = Serve
第二个数组包含有关准备、烹饪和上菜时要做的说明。
[0] = In a large mixing bowl, crack 2 large eggs.
[1] = In a medium-sized frying pan or griddle, heat up a tablespoon of unsalted butter...
[2] = When done, transfer the french toast onto a plate.
当我合并这两个数组时,得到的结果为:
[0] = Prep
[1] = Cook
[2] = Serve
[3] = In a large mixing bowl, crack 2 large eggs.
[4] = In a medium-sized frying pan or griddle, heat up a tablespoon of unsalted butter...
[5] = When done, transfer the french toast onto a plate.
这是实际输出结果。
(
[0] => Array
(
[0] => Array
(
[name] => One
)
[1] => Array
(
[name] => Two
)
[2] => Array
(
[name] => Three
)
[3] => Array
(
[text] => In a large mixing bowl, crack 2 large eggs. Season with a dash of salt. Whisk thoroughly. Pour 2 cups of fresh milk (2%, non-fat or whole milk) and a tablespoon of honey. Whisk again until well combined. 2. Slice or get a slice of bread and dip into the milk and egg mixture. Soak for 30seconds.
)
[4] => Array
(
[text] =>
In a medium-sized frying pan or griddle, heat up a tablespoon of unsalted butter over medium heat until it melts completely. Put the soaked bread and toast it for 3-5 minutes or until golden. Pour 1/4 cup of the mixture. Push the excess liquid to the center and onto the bread. Check the bread every 30-60 seconds. Flip the bread over and toast the other side for equal time
)
[5] => Array
(
[text] =>
When done, transfer the french toast onto a plate. Top with your choice of fruits, with powdered sugar, butter, or Nutella. Then drizzle with your favorite maple syrup. Serve warm and enjoy!!
)
)
)
这是我希望实现的目标。
Array
(
[0] => Array
(
[@type] => HowToStep
[name] => prep
[image] => some image link
[text] => In a large mixing bowl, crack 2 large eggs. Season with a dash of salt. Whisk thoroughly. Pour 2 cups of fresh milk (2%, non-fat or whole milk) and a tablespoon of honey. Whisk again until well combined. 2. Slice or get a slice of bread and dip into the milk and egg mixture. Soak for 30seconds.
)
[1] => Array
(
[@type] => HowToStep
[name] => cook
[image] => some image link
[text] =>
In a medium-sized frying pan or griddle, heat up a tablespoon of unsalted butter over medium heat until it melts completely. Put the soaked bread and toast it for 3-5 minutes or until golden. Pour 1/4 cup of the mixture. Push the excess liquid to the center and onto the bread. Check the bread every 30-60 seconds. Flip the bread over and toast the other side for equal time
)
[2] => Array
(
[@type] => HowToStep
[name] => serve
[image] => some image link
[text] =>
When done, transfer the french toast onto a plate. Top with your choice of fruits, with powdered sugar, butter, or Nutella. Then drizzle with your favorite maple syrup. Serve warm and enjoy!!
)
)
我的代码
$explod1 = saswp_explod_by_semicolon($all_post_meta['saswp_recipe_instructions_name'.$schema_id][0]);{
foreach ($explod1 as $val1)
$instruction1[] = array('name'=>$val1);
// print_r ($instruction1);
}
$explod = saswp_explod_by_semicolon($all_post_meta['saswp_recipe_instructions_'.$schema_id][0]);
// $test = array_push ($explod,$explod1);
foreach ($explod as $val)
// foreach ($explod1 as $val1)
{
$instruction[] = array('text'=>$val);
// array_unique ($instruction);
}
$test1[] = array_merge($instruction1,$instruction);
print_r ($test1);
}
希望你们能帮忙。我已经花了12个小时以上来尝试解决这个问题。阅读和学习。