Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP键将字符串转换为数组_Php_Arrays - Fatal编程技术网

使用PHP键将字符串转换为数组

使用PHP键将字符串转换为数组,php,arrays,Php,Arrays,我试图获取一个带有分隔字符串的数组,并将其转换为带有命名键的多维数组。它很容易做到这一点与数字的关键,但在我的情况下,我想分配一个关键的每一个。键为slug、title和type,对应于每个数组中的键0、1、2 array( 'thisslug|This title|text', 'thatslug|Thats title|text', 'anotherslug|Another title|dropdown', ); 我想和你在一

我试图获取一个带有分隔字符串的数组,并将其转换为带有命名键的多维数组。它很容易做到这一点与数字的关键,但在我的情况下,我想分配一个关键的每一个。键为slug、title和type,对应于每个数组中的键0、1、2

    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。使用数组和联合体。谢谢令人惊叹的。使用数组和联合体。谢谢令人惊叹的。使用数组和联合体。谢谢令人惊叹的。使用数组和联合体。谢谢