Tag Archives: Multidimensional Arrays

PHP Arrays and Type




An array is a data structure that stores one or more similar type of values in a single value. Arrays can be used in many ways to store and organize data quickly and efficiently. It is one of the more useful data types available to any programming language. For example If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this: $cars1="Saab"; $cars2="Volvo"; $cars3="BMW"; However, what if you want […]

PHP stdClass to Array and Array to stdClass Object

PHP stdClass to Array and Array to stdClass Object




I think every PHP coders have come accross Arrays and stdClass Objects (belongs to PHP Predefined Classes). Sometimes it’s very useful convert Objects to Arrays and Arrays to Objects. This is easy if arrays and objects are one-dimensional, but might be little tricky if using multidimensional arrays and objects. This post defines two ultra simple recursive function to convert multidimensional Objects to Arrays and multidimensional Arrays to Objects. Function to Convert stdClass Objects to Multidimensional Arrays