English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

this is one of my php script, i want to know how to assign two dimensional arrays in this script as it might help me to solve this small matter to you..plz...kinda need ur help ...


// Fill up array with names
$a[]="home";
$a[]="shop";
$a[]="car";
$a[]="phone";

//get the q parameter from URL
$q=$_GET["q"];
//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i {
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
{
if ($hint=="")
{
$hint=$a[$i];
}
else
{
$hint=$hint." , ".$a[$i];
}
}
}
}

// Set output to "Search not found" if no hint were found
// or to the correct values
if ($hint == "")
{
$response="Search not found";
}
else
{
$response=$hint;
}

//output the response
echo $response;
?>

2007-10-27 16:16:17 · 1 answers · asked by lil_girl1280 1 in Computers & Internet Programming & Design

1 answers

You ask how to assign TWO dimensional array, but you assign single arrays in your code!
To assign two dims array:
$arr = array ( { "one","two","three" } , { "abc", "def", "ghi" } );
To access: $x = $arr [1] [2] ;
-> $x = "ghi";
Look at www.php.net, array functions: there has been some changes since version 5.

2007-10-27 21:12:31 · answer #1 · answered by just "JR" 7 · 0 0

fedest.com, questions and answers