Page 1 of 1

Array question: print_r[$var] => 1

Posted: Mon Aug 30, 2004 5:34 am
by Lord Sauron
Hi,

A question about a strange array-problem. In fact, it is not really a problem, but just something I do not really understand.

I'm having a multiple select list for selecting your title(s). Suppose I select 'no title' and 3 other titles in the list. When I'm doing print_r($title); the result is:
Array ( [0] => [1] => Prof [2] => Mr [3] => Dr )

The value of 'no title' (first position) is empty as it should be.

I wanted to use the following IF-sentence

Code: Select all

<?php

IF (empty($title[0])) {
    FOR ($a = 1; $a < count($title); $a++) {
        $temporary_title_array[$a-1] = $title[$a];
    }
    $title = $temporary_title_array;
}

?>
But it never entered this IF-sentence. When I did print_r($title[0]), the result was 1. How is that possible?

_________________________________________________________

Code: Select all

<?php

// Code for the creation of a title multiple select list

print("<SELECT class="selectBox" name="title[]" tabindex="1" SIZE="3" MULTIPLE>\n");

IF ((count($title) == 0 OR empty($title))) {
    print("<OPTION value="" SELECTED>No title</OPTION>\n");
}
print("<OPTION value="Prof" SELECTED>Prof</OPTION>\n");
print("<OPTION value="Mr" SELECTED>Mr</OPTION>\n");
print("<OPTION value="Dr" SELECTED>Dr</OPTION>\n");
print("<OPTION value="Ing" SELECTED>Ing</OPTION>\n");

print("</SELECT>\n");

?>

Posted: Mon Aug 30, 2004 10:58 am
by anjanesh
Have you tried :

Code: Select all

IF ($title[0]=="") {...