使用PHP键将字符串转换为数组
我试图获取一个带有分隔字符串的数组,并将其转换为带有命名键的多维数组。它很容易做到这一点与数字的关键,但在我的情况下,我想分配一个关键的每一个。键为slug、title和type,对应于每个数组中的键0、1、2使用PHP键将字符串转换为数组,php,arrays,Php,Arrays,我试图获取一个带有分隔字符串的数组,并将其转换为带有命名键的多维数组。它很容易做到这一点与数字的关键,但在我的情况下,我想分配一个关键的每一个。键为slug、title和type,对应于每个数组中的键0、1、2 array( 'thisslug|This title|text', 'thatslug|Thats title|text', 'anotherslug|Another title|dropdown', ); 我想和你在一
array(
'thisslug|This title|text',
'thatslug|Thats title|text',
'anotherslug|Another title|dropdown',
);
我想和你在一起
array(
array('slug' => 'thisslug', 'title' => 'this title', 'type' => 'text'),
array('slug' => 'thisslug', 'title' => 'this title', 'type' => 'text'),
array('slug' => 'thisslug', 'title' => 'this title', 'type' => 'text')
),
或者使用数组\u组合
:
$keys = array('slug', 'title', 'type');
foreach ($array as $string) {
$row = explode('|', $string); // Explode the string
$result[] = array_combine($keys, $row);
}
或者使用数组\u组合
:
$keys = array('slug', 'title', 'type');
foreach ($array as $string) {
$row = explode('|', $string); // Explode the string
$result[] = array_combine($keys, $row);
}
或者使用数组\u组合
:
$keys = array('slug', 'title', 'type');
foreach ($array as $string) {
$row = explode('|', $string); // Explode the string
$result[] = array_combine($keys, $row);
}
或者使用数组\u组合
:
$keys = array('slug', 'title', 'type');
foreach ($array as $string) {
$row = explode('|', $string); // Explode the string
$result[] = array_combine($keys, $row);
}
对当前数组执行
for
循环,然后分解内容
$arr = array(
'thisslug|This title|text',
'thatslug|Thats title|text',
'anotherslug|Another title|dropdown',
);
$newArr = array();
for($i = 0; $i < count($arr); $i++) {
$strArr = explode('|', $arr[$i]);
$newArr['slugs'] = $strArr[0];
$newArr['title'] = $strArr[1];
$newArr['type'] = $strArr[2];
}
$arr=array(
“thisslug | This title | text”,
“thatslug |这是标题|文本”,
“另一个slug |另一个标题|下拉列表”,
);
$newArr=array();
对于($i=0;$i
对当前数组中的循环执行,然后分解内容
$arr = array(
'thisslug|This title|text',
'thatslug|Thats title|text',
'anotherslug|Another title|dropdown',
);
$newArr = array();
for($i = 0; $i < count($arr); $i++) {
$strArr = explode('|', $arr[$i]);
$newArr['slugs'] = $strArr[0];
$newArr['title'] = $strArr[1];
$newArr['type'] = $strArr[2];
}
$arr=array(
“thisslug | This title | text”,
“thatslug |这是标题|文本”,
“另一个slug |另一个标题|下拉列表”,
);
$newArr=array();
对于($i=0;$i
对当前数组中的循环执行,然后分解内容
$arr = array(
'thisslug|This title|text',
'thatslug|Thats title|text',
'anotherslug|Another title|dropdown',
);
$newArr = array();
for($i = 0; $i < count($arr); $i++) {
$strArr = explode('|', $arr[$i]);
$newArr['slugs'] = $strArr[0];
$newArr['title'] = $strArr[1];
$newArr['type'] = $strArr[2];
}
$arr=array(
“thisslug | This title | text”,
“thatslug |这是标题|文本”,
“另一个slug |另一个标题|下拉列表”,
);
$newArr=array();
对于($i=0;$i
对当前数组中的循环执行,然后分解内容
$arr = array(
'thisslug|This title|text',
'thatslug|Thats title|text',
'anotherslug|Another title|dropdown',
);
$newArr = array();
for($i = 0; $i < count($arr); $i++) {
$strArr = explode('|', $arr[$i]);
$newArr['slugs'] = $strArr[0];
$newArr['title'] = $strArr[1];
$newArr['type'] = $strArr[2];
}
$arr=array(
“thisslug | This title | text”,
“thatslug |这是标题|文本”,
“另一个slug |另一个标题|下拉列表”,
);
$newArr=array();
对于($i=0;$i
使用分解
生成一个数字数组,然后将其转换为关联数组。我看不出所有3个内部数组都有什么不同explode
+使用explode
创建一个数字数组,然后将其转换为关联数组。我看不出所有3个内部数组都有什么不同explode
+使用explode
创建一个数字数组,然后将其转换为关联数组。我看不出所有3个内部数组都有什么不同explode
+使用explode
创建一个数字数组,然后将其转换为关联数组。我看不出所有3个内部数组都有什么不同<代码>爆炸
+Awesome。使用数组和联合体。谢谢令人惊叹的。使用数组和联合体。谢谢令人惊叹的。使用数组和联合体。谢谢令人惊叹的。使用数组和联合体。谢谢