Jump to content

How can i create php hash array ?


colap

Recommended Posts

I tried this:

		$listyear = array();

		for($i=2010;$i<=2020;$i++){
			array_push($listyear,array($i => $i));
		}

 

Array
(
    [0] => Array
        (
            [2010] => 2010
        )

    [1] => Array
        (
            [2011] => 2011
        )

    [2] => Array
        (
            [2012] => 2012
        )

    [3] => Array
        (
            [2013] => 2013
        )

    [4] => Array
        (
            [2014] => 2014
        )

    [5] => Array
        (
            [2015] => 2015
        )

    [6] => Array
        (
            [2016] => 2016
        )

    [7] => Array
        (
            [2017] => 2017
        )

    [8] => Array
        (
            [2018] => 2018
        )

    [9] => Array
        (
            [2019] => 2019
        )

    [10] => Array
        (
            [2020] => 2020
        )

)

 

But i want in this format :

Array(
[2010] = 2010
[2011] = 2011
........
)

Link to comment
https://forums.phpfreaks.com/topic/243282-how-can-i-create-php-hash-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.