Professional Documents
Culture Documents
Q4. Write A Script That Uses The Following Array and The Variable
Q4. Write A Script That Uses The Following Array and The Variable
$w[0] ='r';
$w[1] ='o';
$w[2] ='t';
$w[3] ='a';
$w[4] ='t';
$w[5] ='o';
$w[6] ='r';
$w[7] ='s';
$s='r';
Your script should search the character($s) and display the key(index) of that character($s).
Note that when the values of $s & $w changes your script should continue to work.
<?php
$w[0] ='r';
$w[1] ='o';
$w[2] ='t';
$w[3] ='a';
$w[4] ='t';
$w[5] ='o';
$w[6] ='r';
$w[7] ='s';
$s='r';
foreach($w as $val) {
if(array_search($s, $val)== 0){
echo "Found";
}}?>