Jump to content

array


dcole.ath.cx

Recommended Posts

if I have a dynamic array that I don't know how many places it has, how can I create another array that has the same number of places with the same thing in each:like if array: abc, def, ghi, jklthe new array would be: 0, 0, 0, 0but the array could have been: abcor: abc, def, ghi, jkl, mno, pqr, stu, vwxthen array 0 would have been made or 0, 0, 0, 0, 0, 0, 0, 0

Link to comment
Share on other sites

you wan thte new array to be the same length as the first array?

$array2 = array();for($i=0;$i<sizeof($array1);$i++){     $array2[] = "";}

This would work...but I am sure there must be a better method.

Link to comment
Share on other sites

Just a notice for dcole.ath.cx: aspnetguy used sizeof(), ThePsion5 used count(), these two functions are completely the same, they both count the elements in an array. And I think it's actually $newArray = array_fill(0, $count, 0) if you want the 0 values in the array from the start, and not empty strings.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...