Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does PHP have a Set data structure?

Tags:

php

set

I'm new to PHP, and I can't figure out this basic question. Does PHP have some sort of set or list object? Something like an array, but with the ability to dynamically add or remove any number of objects from it.

like image 287
Jesse Jashinsky Avatar asked Sep 21 '10 21:09

Jesse Jashinsky


People also ask

What is set () in PHP?

PHP isset() Function The isset() function checks whether a variable is set, which means that it has to be declared and is not NULL. This function returns true if the variable exists and is not NULL, otherwise it returns false.

Is set in array PHP?

array is not set. This is also a predefined function in PHP which checks whether an index or a particular key exists in an array or not. It does not evaluate the value of the key for any null values. It returns false if it does not find the key in the array and true in all other possible cases.

What is set data structure?

A set is a data structure that stores unique elements of the same type in a sorted order. Each value is a key, which means that we access each value using the value itself. With arrays, on the other hand, we access each value by its position in the container (the index). Accordingly, each value in a set must be unique.


1 Answers

Yes, you could use the array object and the array functions.

Basically, you could dynamically grow an array using the array_push function, or the $arrayName[] = ... notation (where arrayName is the name of your array).

like image 95
Mike Dinescu Avatar answered Oct 03 '22 07:10

Mike Dinescu