PHP 从数组中提取具有共同名称的元素
PHP extract elements from an array which have a common name
我只想提取名称的特定部分并测试它是否已设置 (isset)?
专用于largeImage_1, largeImage_2等.
这个是我试过的,但是好像return也没有测试过。
if ($_POST['tutorial']) {
foreach ( $_POST['tutorial'] as $key => $value ) {
if ('largeImage' === substr($key, 0 , 10) )
{
echo $value;
}
}
}
Array
(
[title] => title
[tutorial] => Array
(
[1] => Array
(
[largeImage_1] => Array
(
[0] => image.png
[1] => image.png
)
)
[2] => Array
(
[largeImage_2] => Array
(
[0] => image.png
)
)
)
[name] => "";
)
您需要在另一个循环中使用一个循环来访问 'largeImage_1'、'largeImage_2'.
等键
if ($_POST['tutorial']) {
foreach ( $_POST['tutorial'] as $key => $value ) {
foreach ( $value as $k => $v ) {
if ('largeImage' === substr($k, 0 , 10) )
{
//your code here
}
}
}
}
我只想提取名称的特定部分并测试它是否已设置 (isset)?
专用于largeImage_1, largeImage_2等.
这个是我试过的,但是好像return也没有测试过。
if ($_POST['tutorial']) {
foreach ( $_POST['tutorial'] as $key => $value ) {
if ('largeImage' === substr($key, 0 , 10) )
{
echo $value;
}
}
}
Array
(
[title] => title
[tutorial] => Array
(
[1] => Array
(
[largeImage_1] => Array
(
[0] => image.png
[1] => image.png
)
)
[2] => Array
(
[largeImage_2] => Array
(
[0] => image.png
)
)
)
[name] => "";
)
您需要在另一个循环中使用一个循环来访问 'largeImage_1'、'largeImage_2'.
等键if ($_POST['tutorial']) {
foreach ( $_POST['tutorial'] as $key => $value ) {
foreach ( $value as $k => $v ) {
if ('largeImage' === substr($k, 0 , 10) )
{
//your code here
}
}
}
}