0% found this document useful (0 votes)
2 views1 page

PHP Class Item Array Conversion Example

The document defines an Item class with properties for itemid, name, and quantity. It then creates an Item object $i and initializes its properties. It also creates an associative array $rec with the same properties. $i is then dumped to verify its values. $rec is cast to an object and assigned to $j, then $j is cast back to an Item and assigned to $i to show objects and arrays can be converted between each other.

Uploaded by

Nandita Bangera
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

PHP Class Item Array Conversion Example

The document defines an Item class with properties for itemid, name, and quantity. It then creates an Item object $i and initializes its properties. It also creates an associative array $rec with the same properties. $i is then dumped to verify its values. $rec is cast to an object and assigned to $j, then $j is cast back to an Item and assigned to $i to show objects and arrays can be converted between each other.

Uploaded by

Nandita Bangera
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

E:\xampp\htdocs\phpApp\convert\array.

php Tuesday, May 31, 2011 1:10 PM

<?php

class Item {
public $itemid;
public $name;
public $quantity;

public function test()


{
echo "This is a test. Item=" . $this->name . " Qty : ". $this->quantity;
}
};

$i = new Item;
var_dump($i);

$rec = array();
$rec['itemid'] = 1;
$rec['name'] = "iCore3";
$rec['quantity'] = 100;

$i->itemid = 2;
$i->name = "PowerPC";
$i->quantity = 25;
$i->test();

var_dump($rec);
var_dump($i);

$j = (Object)$rec;
var_dump($i);

$i = (Item) $j;
var_dump($i);

?>

-1-

You might also like