Get array length in a PHP class

Viewed 8193

I'm new to object oriented programming in PHP. I made a simple order class with an array property. The method orderLength is not working. I'm getting an error:

Call to undefined method Order::count()

PHP:

<?php
    class Order {
        private $order = array();

        public function setOrder($wert) {
            foreach($wert as $value) {
                $this -> order[] = $value;
            }
        }

        public function orderLength() {
            $length = $this -> count(order);
            return $length;
        }

        public function returnOrder() {
            $value = $this -> order;
            return $value;
        }
    }

    $order = new Order;
    $order -> setOrder(array('Book1', 'Book2', 'Book3', 'Book4'));

    foreach ($order->returnOrder() as $value) {
        echo $value . " <br/>";
    }

    echo "The order length is: " . $order->orderLength();
6 Answers
Related