How to Remove Numeric Keys in PHP Array?
Learn the art of effortlessly eliminating numeric keys from PHP arrays through this comprehensive example. Discover how to remove number-based keys in PHP arrays using practical insights and the array_filter() function.

Join us in this comprehensive example where we'll explore the process of removing numeric keys from PHP arrays with ease. Whether you're a PHP enthusiast or an experienced developer, this article provides a step-by-step guide and practical examples on how to effectively eliminate numeric keys from PHP arrays.
Our approach involves harnessing the power of the array_filter()
function with the is_string
and ARRAY_FILTER_USE_KEY
parameters. By the end of this tutorial, you'll have the expertise to seamlessly delete numeric keys from PHP arrays, enhancing your array manipulation skills in PHP. Embark on this journey of array manipulation with us!
<?php
$myArray = [1 => "One", "Two" => 2, 3 => "Three", "Four" => 4, 5 => "Five", "Six" => 6];
$newArray = array_filter(
$myArray,
function ($k) { return is_string($k); },
ARRAY_FILTER_USE_KEY
);
var_dump($newArray);
?>