How to Remove String Keys in PHP Array?
Learn how to effortlessly eliminate string keys from PHP arrays in this concise tutorial. Discover a simple example of removing string keys in PHP arrays using practical insights and the array_filter() function.

Welcome to a brief yet informative tutorial where we'll explore the process of removing string keys from PHP arrays with ease. Whether you're a PHP enthusiast or a seasoned developer, this article provides a step-by-step guide and practical examples on how to effectively remove string keys from PHP arrays.
Our approach involves leveraging the array_filter()
function with the is_numeric
and ARRAY_FILTER_USE_KEY
parameters. By the end of this tutorial, you'll have the skills to seamlessly delete string keys from PHP arrays, making it a valuable addition to your array manipulation toolkit in PHP. Join us on this journey of array manipulation!
<?php
$myArray = [1 => "One", "Two" => 2, 3 => "Three", "Four" => 4, 5 => "Five", "Six" => 6];
$newArray = array_filter(
$myArray,
function ($k) { return is_numeric($k); },
ARRAY_FILTER_USE_KEY
);
var_dump($newArray);
?>