0

I have a foreach loop that goes through to get information related to a photo.

It's basically this

foreach($medias as $image) {
  $fullImage = $image->imageHighResolutionUrl;
  $standardRes = $image->imageStandardResolutionUrl;
  $caption = $image->caption;
  $createdTime = date("Y-m-d",$image->createdTime);
  $imageCode = $image->code;
}

Now I want to put that data into an array (I'm assuming), so I can sort it by $createdTime then loop through the data to run an "INSERT INTO table" mysql query for each photo.

1 Answer 1

1

I think you can store the data into an array by the following way -

        $sl = 0;
        foreach($medias as $image) {

            $data[$sl]['fullImage']   = $image->imageHighResolutionUrl;
            $data[$sl]['standardRes'] = $image->imageStandardResolutionUrl;
            $data[$sl]['caption']     = $image->caption;
            $data[$sl]['createdTime'] = date("Y-m-d",$image->createdTime);
            $data[$sl]['imageCode']   = $image->code;

            $sl++;
        }


        echo print_r($data);

Now you can a sort the $data variable whatever you want. Then loop through the data and entry into Database.

let me know if you any problem there.

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

Comments

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.