0

My code:

$videos_key = array();
foreach($result[$x]["videos_key"] as $videoskey => $result[$x]["videos_key"] ) 
    {
        $videos_key[$videoskey] = $result[$x]["videos_key"];
    }


print_r($videos_key);

I want to store all values inside $result[$x]["videos_key"] to $videos_key variable

But i am getting this error:

Warning: Invalid argument supplied for foreach()

5
  • $result[$x]["videos_key"] : is it an array? Commented Jun 28, 2017 at 13:28
  • You should first have a look at PHP's documentation: foreach Commented Jun 28, 2017 at 13:48
  • $result[$x]["videos_key"] what is $x and is this an array Commented Jun 28, 2017 at 14:16
  • I am using this code inside an forloop. $x is like 0,1,2,3 @ArtisticPhoenix Commented Jun 28, 2017 at 14:18
  • @SébastienTemprado Yes, it is an array (working) Commented Jun 28, 2017 at 14:19

1 Answer 1

2

That syntax you use is to split your array in key value pairs.

$videos_key = array(
   array('id' => 1, 'value' => 'test')
);

$video_keys_out = array();

foreach($videokey as $key => $value) {
    $videos_keys_out[$key] = $value;
}

something like that. I don't know the rest of your code. So with that syntax you fetch the id and value keypair form the first array and you can work with them.

Sign up to request clarification or add additional context in comments.

1 Comment

Hey videokey is not defined variable. So i am getting 2 errors Notice: Undefined variable: videokey Warning: Invalid argument supplied for foreach()

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.