如何在codeigniter中获取爆炸数据
How to get explode data in codeginter
我在基于 explode 获取数据时遇到一些问题。
例如,如果我有一个包含 $cuisines_category
的数组:
string(26) "Breakfast/Cake - Accept voucher/New Restaurant""
从该数组中它有 2 个内容数据,其中 Breakfast/Cake
为 $cuisines_name_all
,Accept voucher/New_Restaurant
为 $facility_name_all
。
到目前为止我可以 return 爆炸数据,下面的代码:
$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);
是的,我可以 return $facility_name
,但是 $cuisines_name
与 $facility_name
具有相同的内容,而 $cuisines_name
应该没有任何内容
因为我需要 return $cuisines_name
和 $facility_name
从数据库中获取新数据。
伙计们,如果 implode-
不退出,你们知道如何改变数据吗?
这就是你要找的吗?
场景一
$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 )
场景二
$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 )
我在基于 explode 获取数据时遇到一些问题。
例如,如果我有一个包含 $cuisines_category
的数组:
string(26) "Breakfast/Cake - Accept voucher/New Restaurant""
从该数组中它有 2 个内容数据,其中 Breakfast/Cake
为 $cuisines_name_all
,Accept voucher/New_Restaurant
为 $facility_name_all
。
到目前为止我可以 return 爆炸数据,下面的代码:
$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);
是的,我可以 return $facility_name
,但是 $cuisines_name
与 $facility_name
具有相同的内容,而 $cuisines_name
应该没有任何内容
因为我需要 return $cuisines_name
和 $facility_name
从数据库中获取新数据。
伙计们,如果 implode-
不退出,你们知道如何改变数据吗?
这就是你要找的吗?
场景一
$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 )
场景二
$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 )