SaranacLake Posted December 6, 2019 Share Posted December 6, 2019 First off, what are the names for the types of arrays? What do you call an array that uses integers for the key? I think when the key is text it is called an associative array? Anyways... Is there a way to create an array where they keys are integers, but you are defining the first entry? I would like my array to either start with a "1" or maybe "1001". How do I do that? Quote Link to comment https://forums.phpfreaks.com/topic/309641-create-array-with-offset/ Share on other sites More sharing options...
requinix Posted December 6, 2019 Share Posted December 6, 2019 On 12/6/2019 at 3:04 AM, SaranacLake said: First off, what are the names for the types of arrays? Expand In PHP, it's basically either associative or not. 22 minutes ago, SaranacLake said: What do you call an array that uses integers for the key? Expand An array. Sometimes "list". 22 minutes ago, SaranacLake said: I think when the key is text it is called an associative array? Expand Not just string. Associative is when the keys have some sort of particular meaning. You could have an associative array for weekday names. You could also have a non-associative ("list") array for weekday names. And they could even be the same thing. What matters is how the array is used. 22 minutes ago, SaranacLake said: Is there a way to create an array where they keys are integers, but you are defining the first entry? Expand Yes: by creating an array where you define the first entry. Quote Link to comment https://forums.phpfreaks.com/topic/309641-create-array-with-offset/#findComment-1572278 Share on other sites More sharing options...
SaranacLake Posted December 6, 2019 Author Share Posted December 6, 2019 On 12/6/2019 at 3:29 AM, requinix said: Yes: by creating an array where you define the first entry. Expand But I'm not sure of how to do that, I create my array in a llop... while(($file = readdir($handle)) != FALSE){ $photoFiles[] = $file; } If I was doing this out of a loop I guess my first entry could be... $photoFiles[1001] = something; But how do I do that in the loop and not have everything be $photoFiles[1001] ? Quote Link to comment https://forums.phpfreaks.com/topic/309641-create-array-with-offset/#findComment-1572281 Share on other sites More sharing options...
chhorn Posted December 6, 2019 Share Posted December 6, 2019 (edited) You can use a variable there: $photoFiles[$i] = $file; That variable $i can be initialised and incremented. Edited December 6, 2019 by chhorn Quote Link to comment https://forums.phpfreaks.com/topic/309641-create-array-with-offset/#findComment-1572287 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.