Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,994 questions

51,939 answers

573 users

How to delete an element from an array in PHP

4 Answers

0 votes
$arr = array(0 => "php", 1 => "c++", 2 => "c", 3 => "java");
unset($arr[2]);

echo "<pre>";
print_r($arr);
echo "</pre>";

/*
run: 

Array
(
    [0] => php
    [1] => c++
    [3] => java
)

*/

 



answered Jul 20, 2017 by avibootz
0 votes
$arr = array(0 => "php", 1 => "c++", 2 => "c", 3 => "java");
array_splice($arr, 2, 1);

echo "<pre>";
print_r($arr);
echo "</pre>";

/*
run: 

Array
(
    [0] => php
    [1] => c++
    [2] => java
)

*/

 



answered Jul 20, 2017 by avibootz
0 votes
$arr = array("php", "c++", "c", "java", "c#");
unset($arr[1]);
 
echo "<pre>";
print_r($arr);
echo "</pre>";

/*
run: 

Array
(
    [0] => php
    [2] => c
    [3] => java
    [4] => c#
)

*/

 



answered Jul 20, 2017 by avibootz
0 votes
$arr = array("php", "c++", "c", "java", "c#");
array_splice($arr, 1, 1);
 
echo "<pre>";
print_r($arr);
echo "</pre>";
 
/*
run: 
 
Array
(
    [0] => php
    [1] => c
    [2] => java
    [3] => c#
)
 
*/

 



answered Jul 20, 2017 by avibootz

Related questions

2 answers 172 views
2 answers 152 views
1 answer 140 views
1 answer 163 views
1 answer 132 views
...