PHP get array keys from array

0.26K views
no comments
7 Sep 2014 10:57 am
$numbers  = array(
	'one' => 'one'
	,'two' => 'two'
	,'three' => 'three'
	,'four' => 'four'
	,'five' => 'five'
	,'six' => 'six'
	,'seven' => 'seven'
	,'eight' => 'eight'
	,'nine' => 'nine'
	,'ten' => 'ten'
);

foreach($numbers as $num_key=>$num_val){
	$array_keys[$num_key] =$num_key;
}
//RESULT

Array
(
    [one] => one
    [two] => two
    [three] => three
    [four] => four
    [five] => five
    [six] => six
    [seven] => seven
    [eight] => eight
    [nine] => nine
    [ten] => ten
)

 

array(0,1,2,3,3,4,5,5,7,8,7,7)
foreach($numbers as $num_key=>$num_val){
 $array_keys[$num_key] =$num_key;
}

//RESULT

Array
(
    [0] => 0
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 4
    [5] => 5
    [6] => 6
    [7] => 7
    [8] => 8
    [9] => 9
    [10] => 10
    [11] => 11
)

NOTE:Your Email Address will be not shown and please do not add spamming comments because here is REL="NOFOLLOW" on your links and comments also moderated shown.
<code>Put html css or any language code under this tag</code>