Get key after inserting into array PHP -


i'm looking this:

$a = array();  $var1 = 'var1'; $var2 = 'var2';  $i = array_push($a, $var1); $j = array_push($a, $var2);  echo $i; echo $j; 

the expected output be:

0 1 

i want know index of object inserted, able find afterwards. think array_push gives me size of resulting array, not index inserted element

array_push return new number of elements in array, decrement return value 1

try this:

$a = array();  $var1 = 'var1'; $var2 = 'var2';  $i = array_push($a, $var1) - 1; $j = array_push($a, $var2) - 1;  echo $i; echo $j; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -