arfa Posted November 20, 2009 Share Posted November 20, 2009 Adding a value to an array. Why won't this work? $notify_list=file($filename); $notify_list = array_push($notify_list,"$user_em"); foreach($notify_list as $key => $val) { echo "$val<BR>"; } It prints the number of records. the file() is clearly an array and foreach prints as expected. I wonder if it is something to do with the \n at the end of each line? I could easily loop and manually build the new array but.... It seems so simple. Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted November 20, 2009 Share Posted November 20, 2009 http://php.net/manual/en/function.array-push.php array_push returns an int. you can just call it like so and it will work array_push($notify_list,"$user_em"); but since you are just pusing one element into the array, this would be slightly faster $notify_list[] = $user_em; since you don't have the overhead of calling a function Quote Link to comment Share on other sites More sharing options...
arfa Posted November 21, 2009 Author Share Posted November 21, 2009 And on reading the manual (again) more closely I do indeed see: array_push "Returns the new number of elements in the array." Thanks Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted November 21, 2009 Share Posted November 21, 2009 Try this, $notify_list = array(); $notify_list[file($filename)] = $user_em; foreach($notify_list as $key => $val) { echo "$val<BR>"; } James. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.