Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.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_Wordpress_Meta Key - Fatal编程技术网

Php 如何将两个数组的值合并到一个数组中并保存到数据库中

Php 如何将两个数组的值合并到一个数组中并保存到数据库中,php,arrays,wordpress,meta-key,Php,Arrays,Wordpress,Meta Key,我正在处理WordPress上传元字段。当用户上传图像时,图像的大小是二维的,一个是“拇指”,一个是“大”,它们的大小调整得非常完美。我使用不同的元键在数据库中保存两个图像维度路径,如下所示: 对于拇指图像wpc_resize_thumb_图像和大图像wpc_resize_big_图像 当我在DB中保存图像路径时,它保存得非常完美 以下是我在DB中保存它们的代码: 用于大图像 $wpc_resize_big_images = get_post_meta($post->ID, 'wpc_re

我正在处理WordPress上传元字段。当用户上传图像时,图像的大小是二维的,一个是“拇指”,一个是“大”,它们的大小调整得非常完美。我使用不同的元键在数据库中保存两个图像维度路径,如下所示:

对于拇指图像wpc_resize_thumb_图像和大图像wpc_resize_big_图像

当我在DB中保存图像路径时,它保存得非常完美

以下是我在DB中保存它们的代码:

用于大图像

$wpc_resize_big_images = get_post_meta($post->ID, 'wpc_resize_big_images', true);
echo "<pre>";
    print_r($wpc_resize_big_images);
echo "</pre>";
Array
(
    [1] => Array
        (
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg
        )

    [2] => Array
        (
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg
        )
)
Array
(
    [1] => Array
        (
            [wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-212x159.jpg
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg
        )

[2] => Array
    (
        [wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-212x141.jpg
        [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg
    )
)
在数据库中,它将按如下方式保存:

meta_键

wpc_调整大小_大_图像

元值

a:2:{i:1;a:1:{s:18:"wpc_resize_big_img";s:79:"http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg";}i:2;a:1:{s:18:"wpc_resize_big_img";s:79:"http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg";}}
a:2:{i:1;a:1:{s:20:"wpc_resize_thumb_img";s:79:"http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-212x159.jpg";}i:2;a:1:{s:20:"wpc_resize_thumb_img";s:79:"http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-212x141.jpg";}}
和拇指图像

$wpc_resize_big_images = get_post_meta($post->ID, 'wpc_resize_big_images', true);
echo "<pre>";
    print_r($wpc_resize_big_images);
echo "</pre>";
Array
(
    [1] => Array
        (
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg
        )

    [2] => Array
        (
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg
        )
)
Array
(
    [1] => Array
        (
            [wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-212x159.jpg
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg
        )

[2] => Array
    (
        [wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-212x141.jpg
        [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg
    )
)
在数据库中,它将按如下方式保存:

meta_键

wpc_调整大小_拇指_图像

元值

a:2:{i:1;a:1:{s:18:"wpc_resize_big_img";s:79:"http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg";}i:2;a:1:{s:18:"wpc_resize_big_img";s:79:"http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg";}}
a:2:{i:1;a:1:{s:20:"wpc_resize_thumb_img";s:79:"http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-212x159.jpg";}i:2;a:1:{s:20:"wpc_resize_thumb_img";s:79:"http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-212x141.jpg";}}
当我打印它们时,它们会显示如下结果:

大型Imaegs

$wpc_resize_big_images = get_post_meta($post->ID, 'wpc_resize_big_images', true);
echo "<pre>";
    print_r($wpc_resize_big_images);
echo "</pre>";
Array
(
    [1] => Array
        (
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg
        )

    [2] => Array
        (
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg
        )
)
Array
(
    [1] => Array
        (
            [wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-212x159.jpg
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg
        )

[2] => Array
    (
        [wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-212x141.jpg
        [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg
    )
)
拇指图像

$wpc_resize_big_images = get_post_meta($post->ID, 'wpc_resize_big_images', true);
echo "<pre>";
    print_r($wpc_resize_big_images);
echo "</pre>";
Array
(
    [1] => Array
        (
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg
        )

    [2] => Array
        (
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg
        )
)
Array
(
    [1] => Array
        (
            [wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-212x159.jpg
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg
        )

[2] => Array
    (
        [wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-212x141.jpg
        [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg
    )
)
现在我的问题是,如何用一个元键合并并保存两个维度到数据库中,当我打印元键时,它会给出这样的结果

我想要这个

$wpc_resize_big_images = get_post_meta($post->ID, 'wpc_resize_big_images', true);
echo "<pre>";
    print_r($wpc_resize_big_images);
echo "</pre>";
Array
(
    [1] => Array
        (
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg
        )

    [2] => Array
        (
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg
        )
)
Array
(
    [1] => Array
        (
            [wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-212x159.jpg
            [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg
        )

[2] => Array
    (
        [wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-212x141.jpg
        [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg
    )
)

保存多维数组时,可以使用以下代码:

这样,您就可以获得所需的多维数组:

我有两种选择。。1) 不要
保存
,然后再
合并
。。保存已合并的文件。2) 创建一个新表行并分配一个
id
,例如。。。(两者相同),然后可以在查询中使用
join
命令。