Home > Article > Backend Development > PHP changes a loop traversal.
<code> $imagee = $_GET['pic']; foreach ($imagee as $k => $v) { $image[]= array( 'image_src' =>$v, 'image_name' => mt_rand(1, 1111) . '.jpg' ); }</code>
This can only be read one by one. Multiple pics must be submitted to the front desk
The format of each pic is: http://www.baidu.com/1.jpg
or gif
I used another method to get all The image address, the format is as follows
<code> http://www.baidu.com/1.jpg分隔符http://www.baidu.com/2.jpg分隔符http://www.baidu.com/3.jpg</code>
How to make it traverse into the style I want in php?
<code> $imagee = $_GET['pic']; foreach ($imagee as $k => $v) { $image[]= array( 'image_src' =>$v, 'image_name' => mt_rand(1, 1111) . '.jpg' ); }</code>
This can only be read one by one. Multiple pics must be submitted to the front desk
The format of each pic is: http://www.baidu.com/1.jpg
or gif
I used another method to get all The image address, the format is as follows
<code> http://www.baidu.com/1.jpg分隔符http://www.baidu.com/2.jpg分隔符http://www.baidu.com/3.jpg</code>
How to make it traverse into the style I want in php?
Traverse to the style you want? What style. If I guessed what you meant wrong, then explode
?
<code>//这里假设分割符是__(两个英文下划线) $pic = "http://www.baidu.com/1.jpg__http://www.baidu.com/2.jpg__http://www.baidu.com/3.jpg"; $arr = explode('__', $pic); foreach($arr as $key => $v) { unset($arr[$key]); $arr[$key]['image_src'] = $v; $arr[$key]['image_name'] = mt_rand(1, 1111).'.jpg'; } print_r($arr);</code>
I don’t know if I didn’t understand the meaning, but it feels like it’s not much different from the original poster’s code, it just has one more explode