-1

Here is my code

$value = ["300","200","400","500"];

$remove = "300"; 

I want $value as ["200","400","500"];

please answer to this

1
  • Your question make no sense... Could you try to explain what are you trying to do with some more context? Commented Oct 26, 2017 at 12:42

1 Answer 1

3

You can use array_shift() as it will remove the first item in an array:

$value = ["300","200","400","500"];
$remove = array_shift($value);
print_r($value);

This will return:

Array
(
    [0] => 200
    [1] => 400
    [2] => 500
)
Sign up to request clarification or add additional context in comments.

6 Comments

OP probably wants to remove $remove, not necessarily [0].
True @deceze, but without clarification ¯\_(ツ)_/¯
Yeah… "string"? "Trim"? "MySQL"? … ¯\_(ツ)_/¯
I would just do $new = array_diff($value, (array) $remove); 3v4l.org/oDqMj that way you can supply either a string or array of values to remove.
Thanks for your answer I want to delete a value randomly not the first element in an 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.