is_array
is_array(mixed $value): bool
Finds whether a variable is an array.
C C23
#include <stdio.h>
int main(void) {
int a[3] = {1, 2, 3};
int *p = a;
printf("%zu %zu\n", sizeof a, sizeof p);
return 0;
}
12 8
C++ C++26
#include <iostream>
#include <type_traits>
int main() {
int a[3] = {1, 2, 3};
int *p = a;
std::cout << std::boolalpha
<< std::is_array_v<decltype(a)> << " "
<< std::is_array_v<decltype(p)> << "\n";
return 0;
}
true false
C# v11.0.100
object[] xs = { new[] { 1, 2 }, "x" };
Console.WriteLine(xs[0] is Array);
Console.WriteLine(xs[1] is Array);
True False
Go v1.27.4
package main
import (
"fmt"
"reflect"
)
func main() {
values := []any{[]int{1, 2}, "x"}
for _, v := range values {
fmt.Println(reflect.TypeOf(v).Kind() == reflect.Slice)
}
}
true false
Java v27.0.1
public class Main {
public static void main(String[] args) {
Object[] xs = { new int[]{1, 2}, "x" };
Object first = xs[0];
Object second = xs[1];
System.out.println(first instanceof int[]);
System.out.println(second instanceof int[]);
}
}
true false
JavaScript v26.13.1
console.log([Array.isArray([1, 2]), Array.isArray("x")]);
[ true, false ]
PHP v8.6.0
echo json_encode([is_array([1, 2]), is_array("x")]);
[true,false]
Python v3.15.2
print([isinstance(x, list) for x in [[1, 2], "x"]])
[True, False]
Rust v1.99.1
use std::any::Any;
fn main() {
let xs: Vec<Box<dyn Any>> = vec![Box::new([1i32, 2]), Box::new("x".to_string())];
for x in &xs {
println!("{}", x.is::<[i32; 2]>());
}
}
true false
TypeScript v26.13.1
console.log([Array.isArray([1, 2]), Array.isArray("x")]);
[ true, false ]
Language differences
C: has no runtime array type — arrays decay to pointers when passed, and the only visible difference is sizeof: an array name yields the whole array size while a pointer yields only the pointer size (12 vs 8 bytes here on 64-bit platforms).
C++: statically typed languages know types at compile time — std::is_array_v.
C#: is Array on object (types known at compile time).
Go: checks the reflect Kind against Slice.
Java: instanceof on object (types known at compile time).
JavaScript: must use Array.isArray (typeof returns "object" for arrays and cannot distinguish them).
PHP: is_array checks associative/list arrays.
Python: the counterpart is isinstance(x, list).
Rust: applies Any::is::<[T; N]> to a Box<dyn Any>.
TypeScript: same as JS — must use Array.isArray.