How to Remove String Values in PHP Array?

By Hardik Savani November 5, 2023 Category : PHP

Hello Dev,

This article is focused on php array remove string values. This example will help you how to remove string values in array php. This article will give you a simple example of how to remove string values in php array. you can understand a concept of how to delete string from array in php. Alright, let’s dive into the steps.

we will use array_filter() function to remove string values from php array. so, let's see the simple code of how to delete string values from php array.

Example:

index.php

<?php

$myArray = [1, "Two", 3, "Four", 5, "Six"];

$newArray = array_filter($myArray, 'is_numeric');

var_dump($newArray);

?>

Output:

array(3) {

[0]=> int(1)

[2]=> int(3)

[4]=> int(5)

}

I hope it can help you...

Tags :
Shares