php array, to check if a value at key is set or not and update accordingly -


I initialize a php array named $ present, the object of this array is to hold the value of 1 if any name Is present or zero if the name is absent. I have a 10 size name array. Below is the code, but it does not work.

  $ present = array (); ($ I = 0; $ i & lt; = 10; $ i ++) {if (! Isset ($ present [$ name [$ i]])) {$ present [$ name] = 1; } And $ echo $ attendee [$ name [$ i]]; }   

I have also tried:

  $ present = array (); ($ I = 0; $ i & lt; = 10; $ i ++) {If (empty $ $ [$ name]]) {$ present [$ name] = 1; } And $ echo $ attendee [$ name [$ i]]; }   

Thank you!

I think this may be what you are looking for. You're losing $ i when setting $ 1

  $ present = array (); ($ I = 0; $ i & lt; = 10; $ i ++) {if (! Isset ($ present [$ name [$ i]])) {$ present [$ name [$ i]] = 1 ; } And $ echo $ attendee [$ name [$ i]]; }    

Comments