What is the difference between array_pop() and array_push()?



What is the difference between array_pop() and array_push()?..

Answer / Rajesh Srivastava

"array_pop() removes the last element from an array and returns it, while array_push() adds one or more elements to the end of an array. For example:
1. $arr = [1, 2, 3];
2. $lastElement = array_pop($arr); echo $lastElement; // Outputs '3' and $arr contains (1, 2)
3. array_push($arr, 4, 5); echo implode(', ', $arr); // Outputs '1, 2, 4, 5'"

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

What is difference between include and include_once in php?

1 Answers  


What is static in php?

1 Answers  


What is the different between cookies and session in php?

13 Answers  


What and How possible injection in PHP and mysql?

3 Answers   RedAlkemi,


Do csrf tokens expire?

1 Answers  


How to turn on the session support?

1 Answers  


Extract url from this string? It should be flexible for all strings, not for this string only. "yahoo.comyahoo.co.inhotmail.org"

1 Answers   A1 Technology,


Why do we use namespace in php?

1 Answers  


What is query string php?

1 Answers  


What is overloading and overriding in oop?

1 Answers  


What is strcmp () in php?

1 Answers  


What is the name of the scripting engine that powers PHP?

1 Answers  


Categories