0

I have to Do this

My array

array(
   0 => A,
   1 => B,
   2 => C,
   3 => D,
   4 => E,
   5 => F
)

I have array value for example Take C

is there any function available in php in that function i pass this value C and they give me array like this

array(
   0 => C,
   1 => D,
   2 => E,
   3 => F
)

the passing value and after another value is give me in array

2
  • To clarify, you want a function that takes an array and a value, and returns a new array with all items which appear after the value you've provided? I don't think this exists natively in PHP, but it should be trivial to implement... Commented Feb 1, 2016 at 11:19
  • Ok thanks to inform that Commented Feb 1, 2016 at 11:20

2 Answers 2

4

You can use array_slice() in coordination with array_search()

Check out documentation here: http://php.net/manual/en/function.array-slice.php and here: http://php.net/manual/en/function.array-search.php

Example:

<?php
$arr = array(
    0 => A,
    1 => B,
    2 => C,
    3 => D,
    4 => E,
    5 => F
);

$output = array_slice($arr, array_search('C', $arr));
Sign up to request clarification or add additional context in comments.

Comments

0

you can use rang like this:

$alphas = range('C', 'Z');

where C is your character you want your array start, if you want array from C to F:

$alphas = range('C', 'F');

output will be Array ( [0] => C [1] => D [2] => E [3] => F )

4 Comments

but i dont know last value of array
he doesn't need a set of consecutive values. He needs to slice the array starting from a specified value. This is too more specific case answer. The answer must be generic
OP didn't mention that the array will have the whole alphabet
This implies that the OP know the start and end point, however, OP mentioned that they only know starting point, check OP's comment "but i dont know last value of array"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.