array question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

array question

Post by shiznatix »

i have a array that looks kinda like this

Code: Select all

[0] => 'cool things here',
[base_skills] => ''
but when i do

Code: Select all

if (isset($array['base_skills']))
{
    echo 'cool it worked';
}
it dosn't work but i need it to work so if you could help me make it work that would be terrific
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

works for me

Code: Select all

$array = array(0 => 'cool things here', 'base_skills' => '');

if (isset($array['base_skills'])){
	echo 'cool it worked';
}
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

exactly what i am seeing


print_r($qf_map) outputs this ->

Code: Select all

Array
(
    ї1] =>  
                LEFT JOIN
                    mdl_cv_personal_info AS person
                ON
                    person.fk_user_id = base.user_id 
                   
    їbase_skills] => 
)

Code: Select all

if ($qf_map['base_skills'])
{
    echo 'worked for me!';
}
//this does not work ^

//this DOES work
if ($qf_map['base_skills'] == '')
{
    echo 'worked for me right here!';
}
but it is definatly not working, why?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

If $ar['foo'] equals to "", it will evaluate as FALSE. (As explained in http://www.php.net/manual/en/language.c ... uctures.if and http://www.php.net/manual/en/language.t ... an.casting)

Interesting functions: empty, isset, array_key_exists.
Post Reply