In the below code, how do I check if $variable
equals "$one".
<?php
$one = array (1,2,3);
$two = array (4,5,6);
$variables = array ($one, $two);
foreach ($variables as $variable){
//check if the $variable is equal to "$one"
//do stuff that is specific for array $one
}
?>
Simply put, you can't. You can add a key to the values though:
<?php
$one = array (1,2,3);
$two = array (4,5,6);
$variables = array ( 'one' => $one, 'two' => $two);
foreach ($variables as $key => $variable){
//check if the $variable is equal to "$one"
if( $key === 'one' ) {
//do stuff that is specific for array $one
}
}
For more information visit this
<?php
$one = array (1,2,3);
$two = array (4,5,6);
$variables = array ($one, $two);
foreach ($variables as $variable){
//check if the $variable is equal to "$one"
if($variable === $one)
//do stuff
}
?>
foreach ($variables as $variable){
if($variable == $one)//TRUE if $a and $b have the same key/value pairs.
{
}
}
And if you want to check for order and types as well you can do as follow:
foreach ($variables as $variable){
if($variable === $one)
{
}
}
You can check with
if($variable===$one)
You are taking multi dimensional array. Keep in mind and you need to check with "===", not with "==" because its not an variable or even a string.