简体   繁体   中英

php - Store an Array Containing Objects

am using the PocketMine API (not for web), and i have ran a function that returns an array, storing multiple pocketmine\\item\\Item arrays.

This could be thought as an array storing objects.

Basically, what I need to do is store this array, but not in the form as it is. (An array containing objects.) I tried serialize() and json_encode() . Neither of these work in my situation.

Is there any way i can do this? Thanks.

So how do you want your data stored? Is thr object always the same? The object always has the same attributes? If so were do you want to store it? If you want to store in a mysql DB AND the objects always have the same attributes you can foreach every object in the array and insert into the DB.

For example if you have an array of users and the object user is like this: Name, username, password, email

You foreach your array and then insert:

Foreach($users as $user){
  Sql command:  Insert into users (name, username, password, email) values ($user->name, $user->username, $user->password, $user->email)
  }

Is that want you pretend?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM