javascript - assign the value inside the foreach loop to the variable outside the loop or output it outside the loop
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-06-26 10:49:18
0
3
1171

foreach ($doorUserArray as $k =>$v) {

        if (strpos($v, $need) !== false) {
           echo "'$k' => '$v'<br />";
            
        }
    }
    echo $v;//无效
    想把$v的值拿出来 该怎么做
曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(3)
世界只因有你

According to the principle of program execution from top to bottom, declare a variable before foreach, and then assign the value directly inside the foreach loop. If you have any questions, you can reply at any time.

Ty80

Set a global variable and assign the value of $v to the global variable.

伊谢尔伦

Scope issue, before looping, set a variable externally, or extract it and make it a function and return the result

function xyz(){
    ...
    return $v;
}

var toEcho = xyz();
echo toEcho;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template