假设我有一个像这样的数组:
$arr = [
"question" => "What's your name?", "question_key" => "key1",
"question" => "What's your job?", "question_key" => "key2",
"question" => "Where do you live?", "question_key" => "key3",
"question" => "What's your name?", "question_key" => "key1",
"question" => "What's your job?", "question_key" => "key2",
"question" => "Where do you live?", "question_key" => "key3",
"question" => "What's your name?", "question_key" => "key1",
"question" => "What's your job?", "question_key" => "key2",
"question" => "Where do you live?", "question_key" => "key3",
]
我是否可以使用array_chunk
之类的东西并根据question_key拆分它们?就像每次到达键“ question_key” =>“ key3”一样,它将数组拆分成一个块,这样最终会像这样:
$newArr = [
["question" => "What's your name?", "question_key" => "key1",
"question" => "What's your job?", "question_key" => "key2",
"question" => "Where do you live?", "question_key" => "key3"],
["question" => "What's your name?", "question_key" => "key1",
"question" => "What's your job?", "question_key" => "key2",
"question" => "Where do you live?", "question_key" => "key3"],
["question" => "What's your name?", "question_key" => "key1",
"question" => "What's your job?", "question_key" => "key2",
"question" => "Where do you live?", "question_key" => "key3"],
]