我有50個變量在PHP中。我想檢查它們中的每一個,如果它們是真的,則在稱爲$point
的變量中添加2個點。我是新的,所以我寫了幾行,但我認爲我做錯了方式。我該如何做到這一點PHP如果聲明是正確的?
$strenght_point = 0;
if($f_name){$strenght_point++;}
if($l_name){$strenght_point + 2;}
if($full_name){$strenght_point + 2;}
我怎麼能這樣做的權利way.Thanks
更新我的全部功能,在這裏... 它笨控制器功能 希望你們現在明白了很好
功能strength_scale(){
$user_id = $this->uri->segment(2);
$user_name = $this->uri->segment(3);
$query = $this->db->get_where('aoa_user', array('id' => $user_id, 'username' => $user_name));
foreach ($query->result() as $row){
$f_name = $row->f_name;
$l_name = $row->l_name;
$full_name = $row->full_name;
$username = $row->username;
$alias_name = $row->alias_name;
$gender = $row->gender;
$country = $row->country;
$avatar = $row->avatar;
$cover_photo = $row->cover_photo;
$email = $row->email;
$skill = $row->skill;
$other_skills = $row->other_skills;
$ex_time = $row->ex_time;
$about = $row->about;
$company = $row->company;
$company_position = $row->company_position;
$phone = $row->phone;
$facebook = $row->facebook;
$facebook_page = $row->facebook_page;
$google_plus = $row->google_plus;
$twitter = $row->twitter;
$youtube = $row->youtube;
$skype = $row->skype;
$linkedin = $row->linkedin;
$website = $row->website;
$latitude = $row->latitude;
$longitude = $row->longitude;
$verification = $row->verification;
}
$strength_point = 0;
if($f_name){$strength_point++;}
if($l_name){$strength_point + 2;}
if($full_name){$strength_point + 2;}
}
*「我有50個變量」*然後你做錯了什麼。你可能想要使用一個數組。您還需要將新值分配回您的點變量。 – Rizier123
你爲什麼認爲你做錯了?你是否遇到某種形式的錯誤? – castis
你拼寫錯誤。除此之外,你的代碼是正確的。 – durbnpoisn