Converting PDO Array into Static

Hi Experts,

I am building a prototype and I am wondering what is the quickest way to hardcode the following array into my code

(
    [0] => Array
        (
            [date] => 2013-07-01
            [run] => A
            [capacity] => 56
            [vehicle_id] => 37
            [total_trip_pax] => 47
        )

    [1] => Array
        (
            [date] => 2013-07-01
            [run] => B
            [capacity] => 58
            [vehicle_id] => 9
            [total_trip_pax] => 48
        )

    [2] => Array
        (
            [date] => 2013-07-01
            [run] => C
            [capacity] => 0
            [vehicle_id] => 35
            [total_trip_pax] => 13
        )

    [3] => Array
        (
            [date] => 2013-07-02
            [run] => A
            [capacity] => 48
            [vehicle_id] => 36
            [total_trip_pax] => 37
        )

    [4] => Array
        (
            [date] => 2013-07-02
            [run] => B
            [capacity] => 56
            [vehicle_id] => 37
            [total_trip_pax] => 50
        )

    [5] => Array
        (
            [date] => 2013-07-03
            [run] => A
            [capacity] => 58
            [vehicle_id] => 9
            [total_trip_pax] => 49
        )

    [6] => Array
        (
            [date] => 2013-07-03
            [run] => B
            [capacity] => 48
            [vehicle_id] => 17
            [total_trip_pax] => 41
        )

    [7] => Array
        (
            [date] => 2013-07-03
            [run] => C
            [capacity] => 48
            [vehicle_id] => 36
            [total_trip_pax] => 43
        )

    [8] => Array
        (
            [date] => 2013-07-03
            [run] => D
            [capacity] => 0
            [vehicle_id] => 35
            [total_trip_pax] => 2
        )

    [9] => Array
        (
            [date] => 2013-07-04
            [run] => A
            [capacity] => 56
            [vehicle_id] => 37
            [total_trip_pax] => 52
        )

    [10] => Array
        (
            [date] => 2013-07-04
            [run] => B
            [capacity] => 48
            [vehicle_id] => 36
            [total_trip_pax] => 47
        )

    [11] => Array
        (
            [date] => 2013-07-05
            [run] => A
            [capacity] => 56
            [vehicle_id] => 37
            [total_trip_pax] => 47
        )

    [12] => Array
        (
            [date] => 2013-07-05
            [run] => B
            [capacity] => 48
            [vehicle_id] => 17
            [total_trip_pax] => 48
        )

    [13] => Array
        (
            [date] => 2013-07-05
            [run] => C
            [capacity] => 0
            [vehicle_id] => 35
            [total_trip_pax] => 9
        )

    [14] => Array
        (
            [date] => 2013-07-06
            [run] => A
            [capacity] => 58
            [vehicle_id] => 9
            [total_trip_pax] => 49
        )

    [15] => Array
        (
            [date] => 2013-07-06
            [run] => B
            [capacity] => 56
            [vehicle_id] => 37
            [total_trip_pax] => 49
        )

    [16] => Array
        (
            [date] => 2013-07-06
            [run] => C
            [capacity] => 48
            [vehicle_id] => 36
            [total_trip_pax] => 43
        )

    [17] => Array
        (
            [date] => 2013-07-07
            [run] => A
            [capacity] => 58
            [vehicle_id] => 9
            [total_trip_pax] => 54
        )

    [18] => Array
        (
            [date] => 2013-07-07
            [run] => B
            [capacity] => 56
            [vehicle_id] => 37
            [total_trip_pax] => 52
        )

    [19] => Array
        (
            [date] => 2013-07-08
            [run] => A
            [capacity] => 48
            [vehicle_id] => 36
            [total_trip_pax] => 39
        )

    [20] => Array
        (
            [date] => 2013-07-08
            [run] => B
            [capacity] => 56
            [vehicle_id] => 37
            [total_trip_pax] => 53
        )
Thank you
    [21] => Array
        (
            [date] => 2013-07-08
            [run] => C
            [capacity] => 58
            [vehicle_id] => 9
            [total_trip_pax] => 48
        )

)

Open in new window

APD TorontoSoftware DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Can you please post the array again, but instead of using print_r() please use var_export().  

Also, please explain line 190 in the code snippet.  Thanks.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
I am confused, where does this array come from? Can you not just use that?

Other than some simple regular expression replaces on what you have will yield a usable structure (bar the lost "Thank You" in the middle)

<?php
$data = array (
    '0' => array (
            'date' => '2013-07-01',
            'run' => 'A',
            'capacity' => '56',
            'vehicle_id' => '37',
            'total_trip_pax' => '47'
     ),
    '1' => array (
            'date' => '2013-07-01',
            'run' => 'B',
            'capacity' => '58',
            'vehicle_id' => '9',
            'total_trip_pax' => '48'
        ),
    '2' => array
        (
            'date' => '2013-07-01',
            'run' => 'C',
            'capacity' => '0',
            'vehicle_id' => '35',
            'total_trip_pax' => '13'	
        ),

    '3' => array
        (
            'date' => '2013-07-02',
            'run' => 'A',
            'capacity' => '48',
            'vehicle_id' => '36',
            'total_trip_pax' => '37'
		),

    '4' => array
        (
            'date' => '2013-07-02',
            'run' => 'B',
            'capacity' => '56',
            'vehicle_id' => '37',
            'total_trip_pax' => '50'
		),

    '5' => array
        (
            'date' => '2013-07-03',
            'run' => 'A',
            'capacity' => '58',
            'vehicle_id' => '9',
            'total_trip_pax' => '49'
		),

    '6' => array
        (
            'date' => '2013-07-03',
            'run' => 'B',
            'capacity' => '48',
            'vehicle_id' => '17',
            'total_trip_pax' => '41'
		),

    '7' => array
        (
            'date' => '2013-07-03',
            'run' => 'C',
            'capacity' => '48',
            'vehicle_id' => '36',
            'total_trip_pax' => '43'
		),

    '8' => array
        (
            'date' => '2013-07-03',
            'run' => 'D',
            'capacity' => '0',
            'vehicle_id' => '35',
            'total_trip_pax' => '2'
		),

    '9' => array
        (
            'date' => '2013-07-04',
            'run' => 'A',
            'capacity' => '56',
            'vehicle_id' => '37',
            'total_trip_pax' => '52'
		),

    '10' => array
        (
            'date' => '2013-07-04',
            'run' => 'B',
            'capacity' => '48',
            'vehicle_id' => '36',
            'total_trip_pax' => '47'
		),

    '11' => array
        (
            'date' => '2013-07-05',
            'run' => 'A',
            'capacity' => '56',
            'vehicle_id' => '37',
            'total_trip_pax' => '47'
		),

    '12' => array
        (
            'date' => '2013-07-05',
            'run' => 'B',
            'capacity' => '48',
            'vehicle_id' => '17',
            'total_trip_pax' => '48'
		),

    '13' => array
        (
            'date' => '2013-07-05',
            'run' => 'C',
            'capacity' => '0',
            'vehicle_id' => '35',
            'total_trip_pax' => '9'
		),

    '14' => array
        (
            'date' => '2013-07-06',
            'run' => 'A',
            'capacity' => '58',
            'vehicle_id' => '9',
            'total_trip_pax' => '49'
		),

    '15' => array
        (
            'date' => '2013-07-06',
            'run' => 'B',
            'capacity' => '56',
            'vehicle_id' => '37',
            'total_trip_pax' => '49'
		),

    '16' => array
        (
            'date' => '2013-07-06',
            'run' => 'C',
            'capacity' => '48',
            'vehicle_id' => '36',
            'total_trip_pax' => '43'
		),

    '17' => array
        (
            'date' => '2013-07-07',
            'run' => 'A',
            'capacity' => '58',
            'vehicle_id' => '9',
            'total_trip_pax' => '54'
		),

    '18' => array
        (
            'date' => '2013-07-07',
            'run' => 'B',
            'capacity' => '56',
            'vehicle_id' => '37',
            'total_trip_pax' => '52'
		),

    '19' => array
        (
            'date' => '2013-07-08',
            'run' => 'A',
            'capacity' => '48',
            'vehicle_id' => '36',
            'total_trip_pax' => '39'
		),

    '20' => array
        (
            'date' => '2013-07-08',
            'run' => 'B',
            'capacity' => '56',
            'vehicle_id' => '37',
            'total_trip_pax' => '53'
		),
    '21' => array
        (
            'date' => '2013-07-08',
            'run' => 'C',
            'capacity' => '58',
            'vehicle_id' => '9',
            'total_trip_pax' => '48'
		),

);
echo '<pre>' . print_r($data,true) . '</pre>';

Open in new window

Julian HansenCommented:
For a prototype I would put this in an include file and then include it in your test - passing $data to the required processing unit as a parameter - that way it stays out of your main code.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.