PHP changes a loop traversal.

WBOY
Release: 2016-08-04 09:19:35
Original
1046 people have browsed it

<code>    $imagee = $_GET['pic'];
        foreach ($imagee as $k => $v) {
         $image[]= array(
                'image_src'  =>$v,
                'image_name' => mt_rand(1, 1111) . '.jpg'
            );
        }</code>
Copy after login
Copy after login

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.jpgor 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>
Copy after login
Copy after login

How to make it traverse into the style I want in php?

Reply content:

<code>    $imagee = $_GET['pic'];
        foreach ($imagee as $k => $v) {
         $image[]= array(
                'image_src'  =>$v,
                'image_name' => mt_rand(1, 1111) . '.jpg'
            );
        }</code>
Copy after login
Copy after login

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.jpgor 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>
Copy after login
Copy after login

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>
Copy after login

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

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!