本文介绍了具有函数definiiton的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图提取在segment.php中从类段定义的所有函数的内容。从home_segment.php中的类段调用所有三个函数这是从一个类调用多个函数的正确方法。 或建议使用良好的OOP概念。如何改进面向对象编程中的上述类似功能。 我尝试过: segment.php I was trying to pullout the content of all the functions defined from the class segment in segment.php. And calling all the three functions from a class segment in home_segment.php Is this a correct way of calling multiple functions from one class.Or suggest with good OOP's concept. How could I improve the above similar functionality in Object Oriented Programming.What I have tried:segment.php<?php$mysqli = mysqli_connect("localhost","root","","squarellt"); $cid = required_param('id', PARAM_INT); class segment { public function unitseg_set1() { $subject = $mysqli->query('SELECT * FROM order_subject WHERE id='.$cid.''); while($row=$subject->fetch_array() ) { echo '<div>'.$row['chem_name'].'</div>'; } } public function unitseg_set2() { $subject = $mysqli->query('SELECT * FROM order_subject WHERE id='.$cid.''); while($row=$subject->fetch_array() ) { echo '<div>'.$row['physiotherapy_nn'].'</div>'; } } public function unitseg_set3() { $subject = $mysqli->query('SELECT * FROM order_subject WHERE id='.$cid.''); while($row=$subject->fetch_array() ) { echo '<div>'.$row['commun_gg'].'</div>'; } } } ?> home_segment.php home_segment.php require_once('segment.php'); $acc = new segment(); $account1 = $acc->unitseg_set1(); $account2 = $acc->unitseg_set2(); $account3 = $acc->unitseg_set3(); echo $account1; echo $account2; echo $account3; 推荐答案 mysqli = mysqli_connect( localhost, root, , squarellt); mysqli = mysqli_connect("localhost","root","","squarellt"); cid = required_param(' id',PARAM_INT); class segment { public function unitseg_set1() { cid = required_param('id', PARAM_INT); class segment { public function unitseg_set1() { subject = subject = 这篇关于具有函数definiiton的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-15 02:26