简体   繁体   English

Codeigniter数组值检查

[英]Codeigniter array value check

I have an array like these 我有这样的数组

$data=array(
'a'=>'value1',
'b'=>'value2',
'c'=>'value3',
'd'=>array('e'=>'value4','f'=>'value5' ),

);

By using CI how to get the value of 'e' and how to check 'e' is equal to any value or not. 通过使用CI如何获取'e'的值以及如何检查'e'是否等于任何值。

This isn't related to CodeIgniter. 这与CodeIgniter无关。

You can just do this: $data['d']['e'] 您可以这样做: $data['d']['e']

And then to check if it's equal to any value do this: 然后检查它是否等于任何值,请执行以下操作:

if ($data['d']['e'] == $anyValue) {
    // do something
}

You can get the value as in the case of a two dimensional array..$data['d'] will select the array inside.Then get the value of 'e' or 'f' as $data['d']['e'] or $data['d']['f'] . 您可以像在二维数组的情况下那样获取值。.$ data ['d']将选择内部的数组。然后将'e'或'f'的值作为$data['d']['e']$data['d']['f'] If you want to compare try: 如果要比较,请尝试:

if ($data['d']['e'] == $Value) {
 //put your code here.....
}

You can use 您可以使用

echo "<pre>";
print_r($data['d']['e']);
die();

inside your code to check what value you have inside the index 'e'. 在您的代码中检查索引“ e”中包含的值。 Always use this technique. 始终使用此技术。 Very handy. 非常便利。

By the way, this is standard/raw PHP technique, not CI. 顺便说一下,这是标准/原始PHP技术,而不是CI。 You can use raw PHP in CI, there's nothing wrong with that. 您可以在CI中使用原始PHP ,这没有任何问题。

Checking whether the value you have inside index 'e' is equal to a specific value, is a very basic thing you probably might've learned back in high school or grad school. 检查您在索引“ e”中的值是否等于特定值,这是您在高中或研究生时可能已经学到的非常基本的知识。 It's by using an if() statement that you can compare your 'e' value with the specific value you have. 通过使用if()语句,您可以将“ e”值与特定值进行比较。

if($data['d']['e'] == 'somevalue')
{
    //do your work here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM