Home Set Condition to values php
Reply: 2

Set Condition to values php

Bijan Zand
1#
Bijan Zand Published in 2018-02-14 08:56:46Z

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...

Amani
2#
Amani Reply to 2018-02-14 09:03:26Z

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";
}
Mickael Leger
3#
Mickael Leger Reply to 2018-02-14 09:08:36Z

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?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.384852 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO