php - Use a loops values outside of the loop -


i'd use values of loop outside of loop.

            $args = array(                 'post_type' => 'attachment',                 'posts_per_page' => -1,                 'numberposts' => null,             );              if ($attachments) {                 foreach ($attachments $attachment) {                     $image_id = get_attachment_link($attachment->id);                     echo ',';                 }             } 

as loops through spits out range of image id's separated comma.

 1, 2, 3, 4 

after has finished looping i'd use sequence spit out above in function below.

get_jig(array('ids' => $image_id)); 

currently when use loop variable $image_id gives last id, when need of them. apologies noobness. understand it's easy of you, i'm still getting head around php.

looks should able create array before loop , insert ids go.

$ids = array(); // create empty array here if ($attachments) {         foreach ($attachments $attachment) {         $image_id = get_attachment_link($attachment->id);         echo ',';         $ids[] = $image_id; // insert id array     } } 

then use in function looks needs take array

get_jig(array('ids' => $ids)); 

if get_jig doesn't take array, needs comma-separated string, can use implode() create string array:

get_jig(array('ids' => implode(',',$ids))); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -