1

I have loop like this

Code

<?php
for ($i = 'd'; $i<'zz'; $i++) {
    $alpha[] = $i;
}
//$alpha[26] = 'z';

print_r($alpha);

As of now output is like this

Output

Array ( [0] => d [1] => e [2] => f [3] => g [4] => h [5] => i [6] => j [7] => k [8] => l [9] => m [10] => n [11] => o [12] => p [13] => q [14] => r [15] => s [16] => t [17] => u [18] => v [19] => w [20] => x [21] => y....

Expected Output

 Array ( [6] => d [7] => e [8] => f [9] => g [10] => h ....

so what im trying to do is changing the key name key name will starts from [6]=>d,[7]=>e.... so on i need how can i do that in php ?

1
  • yes ur right :) @Epodax Commented Dec 9, 2015 at 7:30

2 Answers 2

3

I'm still a tad unsure if this is what you want, but you can make a simple increment counter like this:

$x = 6; //X is your array's new starting point

for ($i = 'd'; $i<'zz'; $i++) {
    $alpha[$x] = $i;
    $x++; //Increment X with 1
}
Sign up to request clarification or add additional context in comments.

Comments

0

Here you go, just add the index manually

<?php
$index = 6;
for ($i = 'd'; $i<'zz'; $i++) {
    $alpha[$index] = $i;
    $index++;
}

print_r($alpha);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.