如何在codeginter中挖掘数据

时间:2016-07-20 05:29:08

标签: php arrays codeigniter explode

我在根据爆炸获取数据时遇到了一些问题。

示例,如果我有一个$cuisines_category的数组:

string(26) "Breakfast/Cake - Accept voucher/New Restaurant""

从该数组中有2个内容数据,Breakfast/Cake$cuisines_name_allAccept voucher/New_Restaurant$facility_name_all

到目前为止,我可以返回爆炸数据,以下代码:

$split=array_map('trim', explode("-",$cuisines_category));
$cuisines_name_all = (isset($split[0]) === TRUE ? $split[0] : 0);
$facility_name_all = (isset($split[1]) === TRUE ? $split[1] : 0);

$cuisines_name = explode("/", $cuisines_name_all);
$facility_name = explode("/", $facility_name_all);

我的问题是,如果数组$cuisines_category只为$facility_name_all作为此数组的内容怎么样:

string(30) "Online payment available/Deals"

所以我用这段代码更改了我的爆炸代码:

$split=array_map('trim', explode("-",$cuisines_category));
$cuisines_name_all = (isset($split[0]) === TRUE ? $split[0] : 0);
if(isset($split[1])){
    $facility_name_all = $split[1];
}else{
    $facility_name_all = $split[0];
}

$cuisines_name = explode("/", $cuisines_name_all);
$facility_name = explode("/", $facility_name_all);

是的我可以返回$facility_name,但$cuisines_name$facility_name的内容相同$cuisines_name应该没有任何内容

因为我需要返回$cuisines_name$facility_name来从数据库中获取新数据。

如果内爆-没有退出,你知道如何区分数据吗?

1 个答案:

答案 0 :(得分:2)

这就是你在寻找什么?

情景1

$cuisines_category = "Breakfast/Cake - Accept voucher/New Restaurant";

$split = array_map('trim', explode("-", $cuisines_category));

$cuisines_name_all = (count($split) > 1 ) ? $split[0] : 0;
$facility_name_all = (count($split) > 1 ) ? $split[1] : $split[0];

$cuisines_name = explode("/", $cuisines_name_all);
$facility_name = explode("/", $facility_name_all);

<强>输出

cuisines_name: Array ( [0] => Breakfast [1] => Cake )

facility_name: Array ( [0] => Accept voucher [1] => New Restaurant ) 

场景2

$cuisines_category = "Accept voucher/New Restaurant";

$split = array_map('trim', explode("-", $cuisines_category));

$cuisines_name_all = (count($split) > 1 ) ? $split[0] : 0;
$facility_name_all = (count($split) > 1 ) ? $split[1] : $split[0];

$cuisines_name = explode("/", $cuisines_name_all);
$facility_name = explode("/", $facility_name_all);

<强>输出

cuisines_name: Array ( [0] => 0 )

facility_name: Array ( [0] => Accept voucher [1] => New Restaurant )