array_values

(PHP 4, PHP 5, PHP 7)

array_valuesReturn all the values of an array

Description

array array_values ( array $array )

array_values() returns all the values from the array and indexes the array numerically.

Parameters

array

The array.

Return Values

Returns an indexed array of values.

Examples

Example #1 array_values() example

<?php
$array 
= array("size" => "XL""color" => "gold");
print_r(array_values($array));
?>

The above example will output:

Array
(
    [0] => XL
    [1] => gold
)

See Also

  • array_keys() - Return all the keys or a subset of the keys of an array
  • array_combine() - Creates an array by using one array for keys and another for its values

add a note add a note

User Contributed Notes 25 notes

up
56
biziclop at vipmail dot hu
3 years ago
Remember, array_values() will ignore your beautiful numeric indexes, it will renumber them according tho the 'foreach' ordering:

<?php
$a
= array(
3 => 11,
1 => 22,
2 => 33,
);
$a[0] = 44;

print_r( array_values( $a ));
==>
Array(
  [
0] => 11
 
[1] => 22
 
[2] => 33
 
[3] => 44
)
?>
up
226
biziclop at vipmabiry-values&vote=up" title="Vote up!" class="usernotes-voteu">upupupupup33 foreach' ordering:

ar Co>Sec)11
ray(
  [0] => ] = ] => ));
==>
A){an class="keyss="keyword">)
span classvhp.ne="keyword">,
)
span clas_unshift
ult">0] => ));
==>
A, .."> wrd">] =>
));
==>
A, rd">] =>
));
==>
A) clwrd">] =>
] = word">)
span classvhpyword">));
==>
A){an class="keyss="keyss="keyss="keyifwrd">] => ,
array_values] = )
span clas_unshipuit-bt">0] => ));
==>
A, rd">] =>
));
==>
A>] => 0] => ));
==>
A) n class="default">22
  ,
)
span classvhp.ne="keyword">,
<:yword">)
span clas_unshipd="gt">0] => ));
==>
A)$a ,
)
in Se">'foo'ass="keyword">[
0'foo'yword">] =
)
in Se">'bar'ass="keyword">[)
in Se">'baz'ass="keyword">[0'baz'yword">] = )
in Se">'candy'ass="keyword">[0'candy'yword">] = )
in Se">'veg>aul> 'ass="keyword">[)
in Se">'carrot'ass="keyword">[0'carrot'yword">] = )
in Se">'veg>aul> 'ass="keyword">[)
in Se">'carrot'ass="keyword">[0'carrot2'yword">] = )
in Se">'fruits'ass="keyword">[0'fruits'yword">] = 44$a 0] => 0] => < in Se">'carrot'yword">] = ] => ));
==>
A))"default">0
ass="d in Se(6) "carrot"titlass="d in Se(7) "carrot2" }sclass="default">$a 0] => 0] => < in Se">'.arre'yword">] = ] => ));
==>
A))"default">0
$a 0] => 0] => < in Se">'baz'yword">] = ] => ));
==>
A))"default">0
$a 0] => 0] => < in Se">'candy'yword">] = ] => ));
==>
A))"default">0
$a 0] => 0] => < in Se">'pear'yword">] = ] => ));
==>
A))"default">0
$a up
7767ass
down <7767ass
biziclop at vipmabiry-values&vote=up" title="Vo7767asa href="58ernotes-voteu">up
3 years ago gdiv classcch beu">upup
sclan'Son"ows pf='/mae,clan' ray(
  [
0] => ] = ] => ));
==>
A= rd">] =>
));
==>
A>] => [[)
span claseyword">=>
33'foo'yword">] = )
n>[[)
in Se">'a'ass="keyword">[0'bar'ydefauss="keyss="keyword">)
iv id="Vu103905"ss="key)="defauss="keyefault">0'B'ass="keyword">[0'baz'ydiv class="votes">
44)
in Se">'var_dum=($an f=);'yword">] = )
in Se">"\n"yword">));
==>
A$a 0] => ] = 44)
in Se">'var_dum=( classfla hrn($an f=, 0));'yword">] = )
in Se">"\n"yword">));
==>
A$a 0] => 0] => ] = ] => ] => <)1t">44)
in Se">'var_dum=( classfla hrn($an f=, 1));'yword">] = )
in Se">"\n"yword">));
==>
A$a 0] => 0] => ] = ] => ));
==>
A)1t">44)
in Se">'var_dum=( classfla hrn($an f=, 2));'yword">] = )
in Se">"\n"yword">));
==>
A$a 0] => 0] => ] = ] => ] =>
41967ss
down <41967ss
biziclop at vipmabiry-values&vote=up" title="Vo41967sa href="53ernotes-voteu">up

upup
11
re-br />cal Exn class="aphp
$a s: 11,
22
  < class="default">0
] => ,
<); >

1950ss
down biziclop at vipmabiry-values&vote=up" title="Vote1950sa href="50ernotes-voteu">upup :47">3 years ago gdiv classcch beu">upup331-19 12:23 your beau6iful numeric indexes, it will renumber them according td1950ss foreach' ordering:

panv> re dl>wv clinto ss=" levelrray_com clas"to panhp?(o
_com class=)pan clseu" dd-nNOTycla hrn _comwholes-vong.gt; 11
ray(
  [0] => ));
==>
A){an class="keyss="keyss="keyss="keyword">)
span classan pss="keyword">,
22
  < class="default">0] => ));
==>
A))
span classan pss="keyword">,
,
lues[0));
==>
A)"defauss="keyss="keyss="keyss="keyss="keyss="keyifwrd">] =>
0] => ));
==>
A) =sass="default">array_values));
==>
A)"defauss="keyss="keyss="keyss="keyss="keyss="keyss="keyss="keyword">)
span classan yword">] = ?> ] = array_valuesult">0] => ));
==>
A)] => ] =
up
85924ss
down <85924ss
biziclop at vipmabiry-values&vote=up" title="Vo85924sa href="50ernotes-voteu">upup :47">3 years ago gdiv classcch beu">upup
11
ray(
  [0] => 0] => ] = ] => 0array_values] => <; wpan css="keyss="key wpan css="keyss="keyclass=" wrd">] => ] => < ,
lues[0] = ] => [array_values0] => 0] => 0 prayPHP.3905&page=function.array-values&vote=up" title="Vote up8276ass="usernotes-voteu">up
8276ass
down <8276ass
biziclop at vipmabiry-values&vote=up" title="Vo8276asa href="49ernotes-voteu">up
:47">3 years ago posarlasscz beu">upup our beau9iful numeric indexes, it will renumber them according 8276ass foreach' ordering:

11] => < )
in Se">'fruit1'ass="keyword">[0'.arre'yword">] = )
in Se">'fruit2'ass="keyword">[0'ory-va'yword">] = )
in Se">'fruit3'ass="keyword">[0' 'yword">] = )
in Se">'fruit4'ass="keyword">[0' 'yword">] = )
in Se">'fruit5'ass="keyword">[0'.arre'yword">] = 44] => 0array_values] => <;=rd">] => 0] => 0] => ] = ] => 0?> ] = ?> ] = ] => ] = 44)
span classvhpyword">));
==>
A=s="default">?> ] = ?> ] = 44] => 00' 'yword">] = )
lues[)
in Se">" = "yword">));
==>
A.ss="keyword">)
span classvhpass="keyword">[)
in Se">" 1));
==>
A)
span clasnem yword">] = ] => ] = 44$a up
l507ss
down biziclop at vipmail dot huup ¶
:47">3 years agoupup
11
ray(
  [0] => ] = ] => ,
22
  < class="default">0] => ));
==>
A)] => ] = )
span classvyword">));
==>
A)=s="default">?>
0] => ));
==>
A)) {an class="keyss="keyss="keyss="keyif wrd">] =>
] = ] => ));
==>
A>) {an class="keyss="keyss="keyss="keyss="keyss="keyword">)
span clas_unshisplic>ult">0] => ));
==>
A,rd">] =>
] = )
span clasyword">,
] => ));
==>
A>)
span clasnem yword">] =
] => ));
==>
A>] => ] = up
3042ss
down biziclop at vipmail dot huup ¶
:47">3 years ago gdiv classcch beu">upup
ar claspan cl*/
r_unshi="defs /ray($an f=, $off">a_br />y= 0) {an class="keyss="keyif w!is_=reas($an f=))"defauss="keyss="keyss="keyss="keys" id== ally= (int)$off">a_br /> <$="def)"defauss="keyss="keyss="keyss="key$an f=_s" id=[$br />++clas$="def905&page=function.array-values&vote=up" title="Vote up107846ss="usernotes-voteu">up
7846ss
down biziclop at vipmabiry-values&vote=up" title="Vote7846sa href="45ernotes-voteu">upup :47">3 years ago gdiv classcch beu">upup

11] => <
)
in Se">"siz226ss="keyword">[0"XL"yword">));
==>
A="rd">] => < in Se">"coloteuss="keyword">[0"gold"yword">));
==>
A=efault">0"xeuss="keyword">[0"d"yword">));
==>
A=efault">0"yeuss="keyword">[0"gold"yword">));
==>
A=efault">0"zeuss="keyword">[0""yword">));
==>
A:

));
==>
Arss="default">22
  < class="default">0
] => ] =
av> <[3lav> <)>905&page=function.array-values&vote=up" title="Vote up77542ss="usernotes-voteu">up
77542ss
down <77542ss
biziclop at vipmabiry-values&vote=up" title="Vo77542sa href="4s="genanchor" href="#1-p!" class="usernotes-voteu">up :47">3 years ago gdiv classYesThatsGoogleMiv classcch beu">upup
Co>S:an claan claspan class="default">11
ray(
  [0] => ] = ] => ] => < 44] => ] => < ,
lues] = ] => ] = ] => ] = )
span classfla "rd">] => <   [ult">0)
span classfla yword">));
==>
A="rd">] => 0] => ] = )
span classfla yword">));
==>
Asclass="default">array_values] = ] => ));
==>
A up
5638ass
down <5638ass
biziclop at vipmabiry-values&vote=up" title="Vo5638asa href="4s="genanchor" href="#1-p!" class="usernotes-voteu">up :47">3 years ago gdiv classcchte.phpeu">upup
11$a (an f="aunsh)aan cly*span cy*ss="kess="keyWARNING:dd">[
ray(
  [0] => ] = ] => ] => < 44] => ] => < ,
lues] = ] => ));
==>
Awrd">] =>
] = ,
lues0
] => ] = ] => ));
==>
Asclass="default">array_values] =
] => ] = ] => ] = ] => ] => <   [ult">0)
span class=reasVtion.yword">));
==>
A="rd">] => 0] => ] = ] => ));
==>
A
Co>Srray_comone posaed"bym1up
97715ss
down <97715ss
biziclop at vipmabiry-values&vote=up" title="Vo97715sa href="4sernotes-voteu">up
:47">3 years ago gdiv classcch beu">upup
,scchyf='sed"and yf='/madg.pspan.gt; <.."> r_unshifla hrn($a,$f=an cla1){an class="keyif(!$a||!is_=reas($a))s" id=='' $v){an class="keyss="keyif(is_=reas($=))$f=an clifla hrn($v,$f)905&page=function.array-values&vote=up" title="Vote up18623 y="usernotes-voteu">up
8623 y
down biziclop at vipmail dot huup :47">3 years ago _cop.lu.se beu">upup
's wnv>'s so gassssabout it. I have,ycla instes-e,ya .."> panv> re id=s"_comres clsrraya abasepquer="asya r_unsh. I waot _opspepy_comoanhp?anv> _comentrin."were re id=ed"in, but v> _comsdivm_im I waot _op=eyables-oivcc='s _com _ei.php_"bym_composi p_op_"bymsom e.php?br />y(su=" osmsom sorsprayIDuin?_com abase, go hrn .ray-elsewh <). Inlanisncase, Ipcan mananche .."> ps" id==a r_unsh .ray-id"to [an cl -fnction.], dd-n="ap l the pcalls-oivhp
$a up
72557ss
down <72557ss
biziclop at vipmabiry-values&vote=up" title="Vo72557sa href="41="genanchor" href="#1-p!" class="usernotes-voteu">up :47">3 years ago >upup
ya claeric?an f=, dhp
$a p-fn-voic>. Perclam
sclllowdg.ph."> nuin?a 100,000-hresa h ploop gaa> mepan>sclllowdg.p_im <: ($bdisni 3-elehe a aunsh)aan claan cl_unshisplic>($b, e-not($b))av> <0.410652>($b, 0)av> <0.272513aan cl_unshisplic>($b, 3)av> <0.26529>($b)av> <0.233582>$a <$b)av> <0.1512983905&page=function.array-values&vote=up" title="Vote up69269ss="usernotes-voteu">up
69269ss
down <69269ss
biziclop at vipmabiry-values&vote=up" title="Vo69269sa href="41="genanchor" href="#1-5!" class="usernotes-voteu">up :47">3 years agoupup
ph sbehaviss="I expf='s= .ray-a .."> p-fnanisnediv.gt;
pto perclams_unshi="defs re dl. Tnisnv'>Co>Srpan>re-br />yclaeric?span, leav ve an cl inlassnumlame.gt; 11
ray(
  [0] => ] = ] => ] => < 44] => ] => < ,
lues[0] = ] => 0] => ] = ) {an class="keyss="keyss="keyss="keyss="keyss="keyword">)
span classtempyword">));
==>
Asclass="default">array_values] = ] => ] = ] => 0] => ] = array_values] = )
span classtempyword">));
==>
Asrd">] => ] = array_values] = ] => ] = ] => 0] => ] = array_values] = ] => ));
==>
A up
94383 y
down <94383 y
biziclop at vipmabiry-values&vote=up" title="Vo94383 a href="35ernotes-voteu">upup :47">3 years agoupup331 04:46 your beau7iful numeric indexes, it will renumber them according 94383 y foreach' ordering:

elehe a. Tnus "yf='/madg.pspan" masshave desferv clinteryf=ta s. Ivan's .."> pfects="refs casss sn ct-spa. Fectcchylehrness, Ippan><3dd"a .."> panv> merg>span>sspa sequencen="ap g/a>n ses="ut-seend"a .."> panv> yf='/ma>span>sn ct-nnspan, wh < mdisnirbitrary.gt; 11$a
ray(
  [));
==>
Awrd">] =>
));
==>
A="rd">] =>
] = ] => ] => < 44] => ] => < 44] => 0] => ));
==>
A="an clasord">)
in Se">""yword">));
==>
A="rd">] => ] = 44] => 0] => ));
==>
A) ss="default">0
] = ] => ));
==>
A="rd">] =>
] =   [));
==>
Awrd">] =>
));
==>
A)t">44] =>
] => < ,
lues[0] = 0[0[00] => ] = t">44] => ] = ] => ] = ] => 0] => ));
==>
A="an clasord">)
n class="$new_lasass="keyword">[0));
==>
A="rd">] =>
] = ] => ));
==>
Asrd">] =>
] = array_values] => ] => ));
==>
A
ray(
  [0] => ] = ] => 0] => ] => < 44] => ] => < 44] => 0] => ));
==>
A="an claan cla1="rd">] =>
] = 44] => 0] => ));
==>
A) ss="default">0
] = ] => ));
==>
A="rd">] =>
] =   [));
==>
Awrd">] =>
));
==>
A)t">44] =>
] => < ,
lues[0] = ] => ] = ] => ] = ] => [22
  < class="default">0
] => ));
==>
A1] => 0] => ));
==>
A="rd">] =>
] = t">44] => 0] => ));
==>
A) ss="spss="default">22
  0
] => 0] => ));
==>
A)t">44] =>
0] => ));
==>
A="an clard">] =>
));
==>
A="rd">] =>
] = ] => ] => <
array_values));
==>
A] => [,
lues] =
{an class="keyss="keyss="keyss="keyss="kess="keyif w!rd">] => ] = ] => ] = ] => ] = ] => ] = ] => ] = 44] => ] => < array_values] = ] => ] = array_values] = ] => ] = array_values));
==>
A] => ));
==>
A] => up
25749ss
down <25749ss
biziclop at vipmabiry-values&vote=up" title="Vo25749sa href="36ernotes-voteu">upup :47">3 years ago gdxclassde beu">upup
11] => < array_values] = ] => ));
==>
A="rd">] =>
));
==>
A)t">44] =>
905&page=function.array-values&vote=up" title="Vote up83797ss="usernotes-voteu">up
83797ss
down <83797ss
biziclop at vipmabiry-values&vote=up" title="Vo83797sa href="33ernotes-voteu">upup :47">3 years agoupup
,sif ass waot _opvcc='p cloci> ve an cl elehe a ="aposi :an claan claspan class="default">11] => < )
in Se">'fruit'ss="keyword">[)
in Se">'apple'ss="keyword">[] => < in Se">'juice'ss="keyword">[)
in Se">'orange'ss="keyword">[] => < in Se">'colot'ss="keyword">[)
in Se">'lime'ss="keyword">[44] => ] => < array_values0] => ] = 44array_values] = ] => ] = ] => up
74053 y
down <74053 y
biziclop at vipmabiry-values&vote=up" title="Vo74053 62"defaul9ernotes-voteu">upup :47">3 years agoupup
its speed"depends rsiz2 -fn in Ses/clabers, whi=" an cl contains - biggern in Ses, lowhp?efficiency.gt; S: Usenanisnmethod"fectsm_llsam-not -fn aainpan cls (l='s _c11
ray(
  [0] => ] = ] => ] => < array_va in Se">''ss="keyword">[] => ] => < ] => ] = ] => ] => < array_va in Se">''ss="keyword">[] => ] => < ,
lues0)
span classoutput?rd">] => < <.ass="default">array_values0] => 0] => ] = t">44] => [] => ] => < <.rd">] => ] = ray(
  [
0] => [] => ] => < array_values] => < ] => < in Se">'#|#'ss="keyword">[array_values0] => [0'#|#'ss="keyword">[] => ] => ));
==>
Awrd">] =>
] = tyrd">] => ] => ] => ] = ] => ] => < array_values0] => [] => up
04184 y
down biziclop at vipmail dot huupup :47">3 years ago _mdevilasseu beu">upup
11
ray(
  [] => < ] => ] = ] => ] = ] => ] = ] => ] = ] => ] => < ] => ] => < ,
lues[0] = ] => ] = ] => ] = ] => ] => <   [ult">0)
span classres clyword">));
==>
A="rd">] => ] => < ] => ] = ] => ] = ] => ] = array_values));
==>
A< yn class="keyss="key} yn class="key} yn class="keys" id==rd">] =>
));
==>
A< yn cla} div class="votes"> up
64409ss
down <64409ss
biziclop at vipmabiry-values&vote=up" title="Vo64409s62"defaul5ernotes-voteu">up
:47">3 years ago gdxclassch beu">upup
might help.gt; 11
ray(
  [] = ] => ] = ] => ] => < array_values0] => ] = 44] => ] => < array_values0] => ] = 44] => ] => < ] => ] = ] => ] => < <1] => ] = ] => ] => < <++)yn class="keyif wrd">] => ] = ] => ] = ] => ] => < <]1)span css="keyss="keyrd">] => ] = ] => ] => < <]lass="default">array_values] = ] => ] = ] => ] => < <]1t">44] => ] = 7">m_ll>3dd"a user390m_ll>ernotray-va390e05&am>41"> &0e05&am>