如何创建此数组样式

时间:2018-09-27 06:15:03

标签: php

你能帮我吗?您知道如何创建这种样式的数组吗?我想要一个有序的数组,表示ID,标题,描述等...

Array
(
    [0] => Array
        (
            [id] => 1
            [title] => Fitness News
            [description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin tincidunt tempor nunc, sit amet facilisis metus molestie nec. Nulla varius justo et felis euismod bibendum. Vestibulum suscipit tempus viverra. Mauris eros lorem, posuere eget mattis et, euismod id metus. In ac dignissim ligula. fdsfdsfdsfds fdsf fsd
            [image1] => test
            [image1_title] => test
            [created] => 2012-03-26
        )

    [1] => Array
        (
            [id] => 2
            [title] => Recommended Products
            [description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin tincidunt tempor nunc, sit amet facilisis metus molestie nec. Nulla varius justo et felis euismod bibendum. Vestibulum suscipit tempus viverra. Mauris eros lorem, posuere eget mattis et, euismod id metus. In ac dignissim ligula.gdsfdsfdsfdsfds
            [image1] => H
            [image1_title] => H
            [created] => 2012-03-25
        )

    [2] => Array
        (
            [id] => 3
            [title] => New Category
            [description] => This is a new category
            [image1] => 
            [image1_title] => 
            [created] => 2012-03-13
        )

)

希望您能理解。谢谢。

2 个答案:

答案 0 :(得分:1)

您必须在循环中使用此结构并填充子数组。

$main_array = [];
$main_array[] = array(
           'id'=>'value',
           'title'=>'value',
           'description'=>'value',
           'image1'=>'value',
           'image1_title'=>'value',
           'created'=>'value',
    );

答案 1 :(得分:1)

请使用此数组样式...

$array = array();

$subarr['id'] = 1;
$subarr['title'] = "Fitness News";
$subarr['description'] = "Lorem ipsum dolor";
$subarr['image1'] = "test";
$subarr['image1_title'] = "test";
$subarr['created'] = "2012-03-26";
$array[] = $subarr;

$subarr['id'] = 2;
$subarr['title'] = "Recommended Products";
$subarr['description'] = "Lorem ipsum dolor";
$subarr['image1'] = "test";
$subarr['image1_title'] = "test";
$subarr['created'] = "2012-03-26";
$array[] = $subarr;

.....

$finalarray[] = $array;