0

I receive this array in my PHP page after form serializeArray() done on a form in Javascript:

Array
(
    [datas] => Array
        (
            [0] => Array
                (
                    [name] => room_1
                    [value] => a
                )
            [1] => Array
                (
                    [name] => room_2
                    [value] => b
                )
            [2] => Array
                (
                    [name] => room_3
                    [value] => c
                )
        )
)

How can I parse it after during a foreach loop ?

Thanks.


I tried:

foreach ($datas as $key => $item) {
  echo $item;
}

2 Answers 2

1
foreach ($array['datas'] as  $item) {
  echo $item['name'];
  echo $item['value'];
}
Sign up to request clarification or add additional context in comments.

2 Comments

@Misunderstood , too easy ;)
$array = $_POST['your_key']; then you can use $array['datas']
0

If the name of the array is $array,

$arr = $array['datas'];
foreach($arr as $key => $val){
  $name = $val['name'];
  $value = $val['value'];
  }
}

2 Comments

[datas]; should be ['datas']; and [value'] should be ['value']
Thanks. That's what happens when you get old. There is a disconnect between mind and fingers. I can no longer type a single sentence without an error. (e.g. typo in the word sentence just now). I need a syntax checker to compliment the spell check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.