Array question: print_r[$var] => 1

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
Lord Sauron
Forum Commoner
Posts: 85
Joined: Tue Apr 20, 2004 5:53 am
Location: Tilburg, NL

Array question: print_r[$var] => 1

Post 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");

?>
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Have you tried :

Code: Select all

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