Reputation: 417
I have arrays and this arrays have values i need to set Condition to values like that my arrays keys variable and Are changing !
And i want check if my custom value exist print somthing...
if ($arraysValue[$keys] ==1) { print "one"; }
//OR
if ($arraysValue[$keys] ==3) { print "three"; }
Arrays :
Array
(
[0] => 1
[3] => 2
[6] => 3
[9] => 4
[12] => 5
[15] => 8
[18] => 9
)
Array
(
[0] => 1
[4] => 2
[8] => 6
[12] => 9
)
Thanks for any help...
Upvotes: 0
Views: 41
Reputation: 3440
If you want to print the value of each row of your arrays and if the result are only between 1 and 9, you can try something like this :
1/ Create your "alphabet" array where key = the value in letter
$alphabet = array(
"0" => "zero",
"1" => "one",
"2" => "two",
...
"9" => "nine"
)
2/ Loop through your arrays and foreach row, you print the value in letter using your alphabet array :
foreach ($array as $key => $value) {
print($alphabet[$value]);
}
Is this what you are looking for?
Upvotes: 2
Reputation: 2565
If you want to go through all your array items and check each one, you can use foreach
$my_array = array(1,2,3,4,5,6,7,8,9);
foreach($my_array as $array_index=> $array_value){
if($array_value == 1) print "one";
elseif($array_value== 3) print "three";
else print "something else";
}
Upvotes: 2