Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

I have 10 elements of Array, how can i remove 5 array
element, with single function.

Answer Posted / vipul dalwala

Thank you, Pankaj for your comments.

Here is the sample code with both array_splice and
array_slice.

<?PHP

$input = array
("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k");

$output = array_slice($input, 0, 5));

print_r($output); // OUTPUT: Array ( [0] => a [1] => b [2]
=> c [3] => d [4] => e )
print_r($input); // OUTPUT: Array ( [0] => a [1] => b [2]
=> c [3] => d [4] => e [5] => f [6] => g [7] => h [8] => i
[9] => j [10] => k )

$output = array_splice($input, 0, 5));

print_r($output); // OUTPUT: Array ( [0] => a [1] => b [2]
=> c [3] => d [4] => e )
print_r($input); // OUTPUT: Array ( [0] => f [1] => g [2]
=> h [3] => i [4] => j [5] => k )

?>

So again it depends on how you want your input array after
appying the function. As per the question what I understood
is Raheem wants to remove 5 elements from the input array.
Thats why I have suggested array_splice so that after
function my input array has only remaining elements.

Any commets are welcome.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the value of the variable input is a string 1,2,3,4,5,6,7. How would you get the sum of the integers contained inside input?

934


What are the data types in php?

971


What is difference between strstr() and stristr() in PHP?

928


What is a controller in programming?

965


How is traits used in php?

954


Explain Constant in Class?

962


How to get no. of rows using MYSQL function?

1012


Tell me what does the array operator '===' means?

1015


How to set cookies?

944


Explain the difference between $message and $$message?

919


What does mysqli_query return?

894


List some string function name in php?

931


What is xss and csrf?

863


What is the correct line to use within the php.ini file, to specify that 128mb would be the maximum amount of memory that a script may use?

936


Can you pass an array into a function?

1009