如何将数组中的某些字符串连接到另一个多个数组?(PHP,拉拉维尔)


how do I connect some Strings in an array to another multiple array? (PHP, Laravel)

我有两个不同的数组。第一个数组 ($ecode) 是一个多数组。$ecode 的输出如下所示:

Array
(
    [0] => Array
        (
            [ecode] => 200
            [number] => 540
        )
    [2] => Array
        (
            [ecode] => 404
            [number] => 44
        )
    [3] => Array
        (
            [ecode] => 403
            [number] => 9
        )
)

(代码如 404, 200 ....在那里和数量([数字])它们在我的日志文件中存在多少)

在我的 seccond 中,普通数组只是一些字符串:

$ecode_text[] = ['Document Not Found', 'Server busy', 'Forbidden', 'Request executed', '........' ];

我的问题是我需要将字符串放在他的右侧错误代码

像 404 未找到

最后,我的多个数组应如下所示:

    Array
    (
        [0] => Array
            (
                [ecode] => 204
                [number] => 540
                [text] => Request executed
            )
        [2] => Array
            (
                [ecode] => 404
                [number] => 44
                [text] => Document not Found
)

有人可以帮助我吗?我从来没有连接过两个不同的阵列,也不知道从哪里开始。在我的谷歌搜索中,我没有找到解决我的问题的东西。

我正在使用Laravel框架,普通的php就足够了,但如果有人知道Laravel的解决方案,那就太好了。

感谢您的任何帮助!

我尝试过的:

$error_val = array_count_values($ecode_array);
foreach($error_val as $key => $val){
    $errors[] = [
        'number' => $val,
    ];
}
$ecode_text[] =
    [
        404 => 'Document Not Found',
        503 => 'Server busy',
        403 => 'Forbidden',
        204 => 'Request executed',
        307 => 'Moved => temporarily',
        303 => 'Moved temporarily (redirect)',
        206 => 'Partial Content',
        301 => 'Moved permanently (redirect)',
        500 => 'Internal server Error'
        ];
foreach($ecode_text as $ecode => $test){
    if ($ecode == in_array($ecode, $errors)){
        $end_ecode[] = [
            'ecode' => $ecode,
            'test' => $test,
            'number' => $errors['number']
        ];
    }
}

但这对我不起作用..

您需要让规范化文本引用错误代码,因此

例如构建如下数组:
$ecode_text = [404 => 'Document Not Found', 403 => 'Server busy', 401 => 'Forbidden', '........' ];

只是foreach

foreach ($ecode as &$e):
  $e['text'] = $ecode_text[$e['ecode']];
endforeach;