Anonymous
Foreach() сохраняет только последнее значение в массив результатов [дубликат]
Сообщение
Anonymous » 18 сен 2024, 13:00
У меня есть массив $_POST, который выглядит следующим образом
Код: Выделить всё
Array
(
[0] => ed
[1] => smith.co.uk
[2] => http://edsmith.co.uk/smith.jpg
[3] => Published
[4] => ford attenborough
[5] => ford.co.uk
[6] => http://fordattenborough.co.uk/ford.jpg
[7] => Pending Approval
[8] => greg tolkenworth
[9] => greg.co.uk
[10] => http://greg.co.uk/greg.jpg
[11] => In Future
)
У меня есть массив, который выглядит следующим образом
Код: Выделить всё
"unique_id()" => array(
"partner_name" => array(
"id" => $shortname."_partner_name",
"name" => "the_partner_name",
"desc" => "The partner's name",
"type" => "text",
"value" => "",
"placeholder" => "partner name",
),
"partner_url" => array(
"id" => $shortname."_partner_url",
"name" => "the_partner_url",
"desc" => "Url of the partner",
"type" => "text",
"value" => "",
"placeholder" => "partner url",
),
"partner_logo" => array(
"id" => $shortname."_partner_logo",
"name" => "the_partner_logo",
"desc" => "Logo of the partner",
"type" => "text",
"value" => "",
"placeholder" => "partner logo",
),
"partner_status" => array(
"id" => $shortname."_partner_status",
"name" => "the_partner_status",
"desc" => "The status of the partner",
"type" => "select",
"options" => array("Select Option","Publish", "Pending Approval", "In Future"),
"std" => "Select Option",
)),
Отправленный массив хранится в этой переменной $posted['partner_crud'], и я пытаюсь использовать foreach
Код: Выделить всё
$u = uniqid();
foreach($posted['partner_crud'] as $key => $value){
$add_this_array = array($u => array(
"partner_name" => array(
"id" => $shortname."_partner_name",
"name" => "the_partner_name",
"desc" => "The partner's name",
"type" => "text",
"value" => $value,
"placeholder" => "partner name",
),
"partner_url" => array(
"id" => $shortname."_partner_url",
"name" => "the_partner_url",
"desc" => "Url of the partner",
"type" => "text",
"value" => $value,
"placeholder" => "partner url",
),
"partner_logo" => array(
"id" => $shortname."_partner_logo",
"name" => "the_partner_logo",
"desc" => "Logo of the partner",
"type" => "text",
"value" => $value,
"placeholder" => "partner logo",
),
"partner_status" => array(
"id" => $shortname."_partner_status",
"name" => "the_partner_status",
"desc" => "The status of the partner",
"type" => "select",
"value" => $value,
"options" => array("Select Option","Publish", "Pending Approval", "In Future"),
"std" => "Select Option",
)));
}
чтобы сгенерировать четыре массива в формате, как я показал выше. Проблема в том, что я могу создать массив только с первым значением. Как я могу создать все четыре массива?.
Подробнее здесь:
https://stackoverflow.com/questions/220 ... sult-array
1726653645
Anonymous
У меня есть массив $_POST, который выглядит следующим образом [code]Array ( [0] => ed [1] => smith.co.uk [2] => http://edsmith.co.uk/smith.jpg [3] => Published [4] => ford attenborough [5] => ford.co.uk [6] => http://fordattenborough.co.uk/ford.jpg [7] => Pending Approval [8] => greg tolkenworth [9] => greg.co.uk [10] => http://greg.co.uk/greg.jpg [11] => In Future ) [/code] У меня есть массив, который выглядит следующим образом [code]"unique_id()" => array( "partner_name" => array( "id" => $shortname."_partner_name", "name" => "the_partner_name", "desc" => "The partner's name", "type" => "text", "value" => "", "placeholder" => "partner name", ), "partner_url" => array( "id" => $shortname."_partner_url", "name" => "the_partner_url", "desc" => "Url of the partner", "type" => "text", "value" => "", "placeholder" => "partner url", ), "partner_logo" => array( "id" => $shortname."_partner_logo", "name" => "the_partner_logo", "desc" => "Logo of the partner", "type" => "text", "value" => "", "placeholder" => "partner logo", ), "partner_status" => array( "id" => $shortname."_partner_status", "name" => "the_partner_status", "desc" => "The status of the partner", "type" => "select", "options" => array("Select Option","Publish", "Pending Approval", "In Future"), "std" => "Select Option", )), [/code] Отправленный массив хранится в этой переменной $posted['partner_crud'], и я пытаюсь использовать foreach [code]$u = uniqid(); foreach($posted['partner_crud'] as $key => $value){ $add_this_array = array($u => array( "partner_name" => array( "id" => $shortname."_partner_name", "name" => "the_partner_name", "desc" => "The partner's name", "type" => "text", "value" => $value, "placeholder" => "partner name", ), "partner_url" => array( "id" => $shortname."_partner_url", "name" => "the_partner_url", "desc" => "Url of the partner", "type" => "text", "value" => $value, "placeholder" => "partner url", ), "partner_logo" => array( "id" => $shortname."_partner_logo", "name" => "the_partner_logo", "desc" => "Logo of the partner", "type" => "text", "value" => $value, "placeholder" => "partner logo", ), "partner_status" => array( "id" => $shortname."_partner_status", "name" => "the_partner_status", "desc" => "The status of the partner", "type" => "select", "value" => $value, "options" => array("Select Option","Publish", "Pending Approval", "In Future"), "std" => "Select Option", ))); } [/code] чтобы сгенерировать четыре массива в формате, как я показал выше. Проблема в том, что я могу создать массив только с первым значением. Как я могу создать все четыре массива?. Подробнее здесь: [url]https://stackoverflow.com/questions/22009644/foreach-only-saving-last-value-to-result-array[/url]