如何从php中的嵌套数组中获取值

时间:2021-06-29 22:07:31

When I submit the form by post method i am getting the value like this for an array.

当我通过post方法提交表单时,我得到了这样的数组值。

 array
 'custom_profile_type' => 
    array
       0 => string '39242' (length=5)
    'satori_programme' => string '0' (length=1)

I want the value 39242 from above array. How to get that? Any idea guys ?

我想要从数组上面的值39242。怎么弄?任何想法的家伙?

3 个解决方案

#1


5  

Access it like..

访问它像..

echo $yourarray['custom_profile_type'][0];

#2


4  

 echo  $array['custom_profile_type'][0];

#3


3  

Access Using The Below Code | You can add loop to get all values like below

使用以下代码访问|您可以添加循环以获取如下所示的所有值

Static Code

  echo  $array['custom_profile_type'][6]
  echo  $array['custom_profile_type'][0]

Dynamic Code

<?php
$array = $_POST['custom_profile_type'];

foreach($array as $key => $value) {
    echo $key . " => " . $value;
}
?>

#1


5  

Access it like..

访问它像..

echo $yourarray['custom_profile_type'][0];

#2


4  

 echo  $array['custom_profile_type'][0];

#3


3  

Access Using The Below Code | You can add loop to get all values like below

使用以下代码访问|您可以添加循环以获取如下所示的所有值

Static Code

  echo  $array['custom_profile_type'][6]
  echo  $array['custom_profile_type'][0]

Dynamic Code

<?php
$array = $_POST['custom_profile_type'];

foreach($array as $key => $value) {
    echo $key . " => " . $value;
}
?>