Php Count() Function

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 lớn undefined method Order::count()

PHP:

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) eđến $value . " "; emang lại "The order length is: " . $order->orderLength();

Bạn đang xem: Php count() function

*

*

*

*

*

Xem thêm: Tải Game Hitman - Hitman: Absolution

You have not defined a method count for your class. The way you have sầu done it, it looks lượt thích you are calling the count method of your class, giving order as an argument.

$length=count($this->order);
Simply you miske that line

$this -> count(order);Your class has no member functions with the name count, so remove that:

this ->
Assign the value to the variable $order và then write the code for getting the count:

$order = $order -> setOrder(array("Book1", "Book2", "Book3", "Book4"));emang đến "The order length is: ".$order->orderLength();
Thanks for contributing an answer lớn Staông chồng Overflow!

Please be sure to lớn answer the question. Provide details & nội dung your research!

But avoid

Asking for help, clarification, or responding khổng lồ other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.


Post Your Answer Discard

By clicking “Post Your Answer”, you agree khổng lồ our terms of service, privacy policy & cookie policy


site kiến thiết / biểu tượng logo © 2021 Staông chồng Exchange Inc; user contributions licensed under cc by-sa. rev2021.6.29.39606


Your privacy

By clicking “Accept all cookies”, you agree Stachồng Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.