duaijiao0648 2014-03-20 12:45
浏览 82
已采纳

按值排序数组

I have this post array

Array ( 
[imgurl_3] => http://localhost/wordpress/wp-content/uploads/2014/03/05-239x300.jpg
[imgtekst_3] => Write a text for the slide 
[imgurl_4] => http://localhost/wordpress/wp-content/uploads/2014/03/img_2184-300x225.jpg
[imgtekst_4] => Write a text for the slide 
[update_gallery] => Save changes )

The numbers in the end of the imgurl and imgtekst are dynamic. So. I want to pair the imgurl_3 & imgtekst_3, and so on. To update into a database.

Any smart PHP functions for this?

Thanks

  • 写回答

2条回答 默认 最新

  • dongpo4197 2014-03-20 12:54
    关注
        $array = [
            'imgurl_3' => 'http://localhost/wordpress/wp-content/uploads/2014/03/05-239x300.jpg',
            'imgtekst_3' => 'Write a text for the slide',
            'imgurl_4' => 'http://localhost/wordpress/wp-content/uploads/2014/03/img_2184-300x225.jpg',
            'imgtekst_4' => 'Write a text for the slide',
            'update_gallery' => 'Save changes'
        ];
        $output = [];
        foreach ($array as $key => $item) {
            $intKey = filter_var($key, FILTER_SANITIZE_NUMBER_INT);
            if ($intKey) {
                $key = preg_replace('/_\d/', '', $key);
                $output[$intKey][$key] = $item;
            }
        }
        print_r($output);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题