Re: [PHP] Re: Array Search - Solved
At 01:31 PM 3/25/2011, João Cândido de Souza Neto wrote: It´s a job to array_key_exists function. -- João Cândido de Souza Neto Ethan Rosenberg eth...@earthlink.net escreveu na mensagem news:0lim00hi3ihny...@mta4.srv.hcvlny.cv.net... Dear List - Here is a code snippet: $bla = array(g1 = $results[7][6], h1 = $results[7][7]); print_r($bla); $value = h1; $locate1 = array_search($value, $bla); echo This is locate ; print_r($locate1); if(in_array($value, $bla)) print_r($bla); Neither the array_search or the in_array functions give any results. I have tried it with both h1 and h1; $results[7][6] = Wn; $results[7][7] = Wr; This is a chess board where g1 and h1 are the coordinates and the results array contains the pieces at that coordinate. What am I doing wrong? Advice and comments please. Thanks. Ethan Rosenberg Thank you. It works!! Ethan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Search
It´s a job to array_key_exists function. -- João Cândido de Souza Neto Ethan Rosenberg eth...@earthlink.net escreveu na mensagem news:0lim00hi3ihny...@mta4.srv.hcvlny.cv.net... Dear List - Here is a code snippet: $bla = array(g1 = $results[7][6], h1 = $results[7][7]); print_r($bla); $value = h1; $locate1 = array_search($value, $bla); echo This is locate ; print_r($locate1); if(in_array($value, $bla)) print_r($bla); Neither the array_search or the in_array functions give any results. I have tried it with both h1 and h1; $results[7][6] = Wn; $results[7][7] = Wr; This is a chess board where g1 and h1 are the coordinates and the results array contains the pieces at that coordinate. What am I doing wrong? Advice and comments please. Thanks. Ethan Rosenberg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: array to var - with different name
On 01/20/2011 05:26 PM, Tommy Pham wrote: On Thu, Jan 20, 2011 at 2:49 PM, Shawn McKenzie nos...@mckenzies.net wrote: On 01/20/2011 04:28 PM, Donovan Brooke wrote: Hello again! I'm trying to find a good way to convert array key/value's to variable name values... but with the caveat of the name being slightly different than the original key (to fit my naming conventions). first, I (tediously) did this: --- if (isset($_GET['f_action'])) { $t_action = $_GET['f_action']; } if (isset($_POST['f_action'])) { $t_action = $_POST['f_action']; } if (isset($_GET['f_ap'])) { $t_ap = $_GET['f_ap']; } if (isset($_POST['f_ap'])) { $t_ap = $_POST['f_ap']; } --- Instead, I wanted to find *all* incoming f_ keys in the POST/GET array, and convert them to a variable name consisting of t_ in one statement. I then did this test and it appears to work (sorry for email line breaks): - $a_formvars = array('f_1' = '1','f_2' = '2','f_3' = '3','f_4' = '4','f_5' = '5','f_6' = '6',); $t_string = ; foreach ($a_formvars as $key = $value) { if (substr($key,0,2) == 'f_') { $t_string = $t_string . t_ . substr($key,2) . =$value; parse_str($t_string); } } - I figure I can adapt the above by doing something like: $a_formvars = array_merge($_POST,$_GET); However, I thought I'd check with you all to see if there is something I'm missing. I don't speak PHP that well and there may be an easier way. Thanks, Donovan I'm sure you have a good reason for doing this? It is needlessly adding complexity, but here is a one liner (not tested): extract(array_combine(str_replace('f_', 't_', array_keys($_POST)), array_values($_POST))); -- Thanks! -Shawn http://www.spidean.com That will fail if by chance that he has a form name set to a_f_something or similar along the line. Or a possible attack that comes in the form submission. Regards, Tommy Yes, so maybe a simple preg_replace(): extract(array_combine(preg_replace('/^f_/', 't_', array_keys($_POST)), array_values($_POST))); You could also just replace with '' and then use the extract prefix of 't'. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array to var - with different name
On 01/20/2011 04:28 PM, Donovan Brooke wrote: Hello again! I'm trying to find a good way to convert array key/value's to variable name values... but with the caveat of the name being slightly different than the original key (to fit my naming conventions). first, I (tediously) did this: --- if (isset($_GET['f_action'])) { $t_action = $_GET['f_action']; } if (isset($_POST['f_action'])) { $t_action = $_POST['f_action']; } if (isset($_GET['f_ap'])) { $t_ap = $_GET['f_ap']; } if (isset($_POST['f_ap'])) { $t_ap = $_POST['f_ap']; } --- Instead, I wanted to find *all* incoming f_ keys in the POST/GET array, and convert them to a variable name consisting of t_ in one statement. I then did this test and it appears to work (sorry for email line breaks): - $a_formvars = array('f_1' = '1','f_2' = '2','f_3' = '3','f_4' = '4','f_5' = '5','f_6' = '6',); $t_string = ; foreach ($a_formvars as $key = $value) { if (substr($key,0,2) == 'f_') { $t_string = $t_string . t_ . substr($key,2) . =$value; parse_str($t_string); } } - I figure I can adapt the above by doing something like: $a_formvars = array_merge($_POST,$_GET); However, I thought I'd check with you all to see if there is something I'm missing. I don't speak PHP that well and there may be an easier way. Thanks, Donovan I'm sure you have a good reason for doing this? It is needlessly adding complexity, but here is a one liner (not tested): extract(array_combine(str_replace('f_', 't_', array_keys($_POST)), array_values($_POST))); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: array to var - with different name
On Thu, Jan 20, 2011 at 2:49 PM, Shawn McKenzie nos...@mckenzies.net wrote: On 01/20/2011 04:28 PM, Donovan Brooke wrote: Hello again! I'm trying to find a good way to convert array key/value's to variable name values... but with the caveat of the name being slightly different than the original key (to fit my naming conventions). first, I (tediously) did this: --- if (isset($_GET['f_action'])) { $t_action = $_GET['f_action']; } if (isset($_POST['f_action'])) { $t_action = $_POST['f_action']; } if (isset($_GET['f_ap'])) { $t_ap = $_GET['f_ap']; } if (isset($_POST['f_ap'])) { $t_ap = $_POST['f_ap']; } --- Instead, I wanted to find *all* incoming f_ keys in the POST/GET array, and convert them to a variable name consisting of t_ in one statement. I then did this test and it appears to work (sorry for email line breaks): - $a_formvars = array('f_1' = '1','f_2' = '2','f_3' = '3','f_4' = '4','f_5' = '5','f_6' = '6',); $t_string = ; foreach ($a_formvars as $key = $value) { if (substr($key,0,2) == 'f_') { $t_string = $t_string . t_ . substr($key,2) . =$value; parse_str($t_string); } } - I figure I can adapt the above by doing something like: $a_formvars = array_merge($_POST,$_GET); However, I thought I'd check with you all to see if there is something I'm missing. I don't speak PHP that well and there may be an easier way. Thanks, Donovan I'm sure you have a good reason for doing this? It is needlessly adding complexity, but here is a one liner (not tested): extract(array_combine(str_replace('f_', 't_', array_keys($_POST)), array_values($_POST))); -- Thanks! -Shawn http://www.spidean.com That will fail if by chance that he has a form name set to a_f_something or similar along the line. Or a possible attack that comes in the form submission. Regards, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: array or list of objects of different types
var_dump( array( true , 12 , php already does this ) ); array(3) { [0]= bool(true) [1]= int(12) [2]= string(21) php already does this } :) Yeah. But this feature of PHP is a boon if used carefully and a curse if careless. You can get AMAZING results if you're not careful to check the data types ;) And that's why language like C# and java supports to restrict the type of data a collection can hold. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array or list of objects of different types
Php Developer wrote: Hi all, I want to be able to have an array of elements of different types. As an example: the first element is a boolean, the second is an integer, and the thirs is a string. In php there is no typing, i'm just wondering if there is a way to have that, it would be a lot better than having an array of strings and have to convert each element. var_dump( array( true , 12 , php already does this ) ); array(3) { [0]= bool(true) [1]= int(12) [2]= string(21) php already does this } :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: array or list of objects of different types
On 04/03/10 05:42, Nathan Rixham wrote: Php Developer wrote: Hi all, I want to be able to have an array of elements of different types. As an example: the first element is a boolean, the second is an integer, and the thirs is a string. In php there is no typing, i'm just wondering if there is a way to have that, it would be a lot better than having an array of strings and have to convert each element. var_dump( array( true , 12 , php already does this ) ); array(3) { [0]= bool(true) [1]= int(12) [2]= string(21) php already does this } :) Yeah. But this feature of PHP is a boon if used carefully and a curse if careless. You can get AMAZING results if you're not careful to check the data types ;) -- Nilesh Govindarajan Site Server Administrator www.itech7.com मेरा भारत महान ! मम भारत: महत्तम भवतु ! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Search Not Working?
Alice Wei wrote: Hi, I have two arrays here that I have combined into a new array, as shown here: $from = explode(-, $from); $change = explode(-,$change); $new_array = array_combine($from,$change); I then tried reading it from a file and do string matches, trying to find out the key using the array_search of the individual array elements. I seem to have no such luck, even when I copied one of the elements after I do a print_r($new_array); Here is the code, foreach ($lines2 as $line_num = $line2) { $style_line_num = $line_num+3; if(preg_match(/^style/,$line2)) { if(preg_match(/inkscape:label/,$lines2[$style_line_num])) { $location = explode(=,$lines2[$style_line_num]); $location2 = substr($patient_location[1],1,-6); if(in_array($location2, $from)) { $key= array_search($location2,$new_array); //Find out the position of the index in the array echo Key . $key . br; //This only gives me a blank space after the word Key } } //end preg_match inkscape } //If preg_match style I looked at the example from http://php.net/manual/en/function.array-search.php, and looks like what I am trying to do here is possible, and yet, why am I not getting a proper key return? Thanks for your help. Alice _ Hotmail: Powerful Free email with security by Microsoft. http://clk.atdmt.com/GBL/go/201469230/direct/01/ It's not clear what you are doing, but here is the problem that you are asking about. array_combine() builds an array using the values from $from as the keys of the new array and the values from change as the values of the new array. So here, if $locations2 is a value in the $from array: if(in_array($location2, $from)) { But here you are searching the values of $new_array which are copies of the values from $to. $key= array_search($location2,$new_array); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Search Not Working?
On Wed, 10 Mar 2010 09:52:30 -0500, aj...@alumni.iu.edu (Alice Wei) wrote: Hi, I have two arrays here that I have combined into a new array, as shown here: $from = explode(-, $from); $change = explode(-,$change); $new_array = array_combine($from,$change); I then tried reading it from a file and do string matches, trying to find out the key using the array_search of the individual array elements. I seem to have no such luck, even when I copied one of the elements after I do a print_r($new_array); Here is the code, foreach ($lines2 as $line_num = $line2) { $style_line_num = $line_num+3; if(preg_match(/^style/,$line2)) { if(preg_match(/inkscape:label/,$lines2[$style_line_num])) { $location = explode(=,$lines2[$style_line_num]); $location2 = substr($patient_location[1],1,-6); if(in_array($location2, $from)) { $key= array_search($location2,$new_array); //Find out the position of the index in the array echo Key . $key . br; //This only gives me a blank space after the word Key } } //end preg_match inkscape } //If preg_match style I looked at the example from http://php.net/manual/en/function.array-search.php, and looks like what I am trying to do here is possible, and yet, why am I not getting a proper key return? Thanks for your help. Alice I have a very handy utility for problems like this: // Expand string array, list all terms function larec($array, $name) // List array recursive { if (is_array($array)) { $j = count ($array); $temp = array_keys($array); $i = 0; while ($i $j) { if(isset($array[$temp[$i]])) { $new_line = $name.['.$temp[$i].']; larec ($array[$temp[$i]], $new_line); } $i++; } } else { echo 'p'.$name.' = '.$array.'/p'; } } If you have some array $foo then larec($foo,'Foo'); will list all the elements of $foo recursively, without any obvious limits. This makes it very easy to see what you have actually got, as opposed to what you thought you would get. The following is an abridged example of the result of listing an array $wkg_sys of mine, using: larec ($wkg_sys,'Sys'); Sys['class'] = W Sys['style']['0']['wkg_style'] = basic_tab Sys['style']['0']['pad'] = Sys['style']['0']['stripe'] = 0 Sys['style']['1']['wkg_style'] = nrml_style Sys['style']['1']['pad'] = 1 Sys['style']['1']['stripe'] = 0 Sys['valid'] = 1 Sys['entries'] = 15 Sys['f_title'] = Developmental Web Page Sys['version'] = IF1.4 Sys['ident'] = 0800 Sys['directory_id'] = Sys['index'] = 2 Sys['date'] = CCY2N Clancy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array
'Twas brillig, and Jim Lucas at 10/08/09 16:29 did gyre and gimble: $d = array( home_page, member_services, member_services_login, network, resource_center, verse_of_the_day_activate, ); Ahh someone else who always puts a closing , on the end of array definitions to cut down on VCS diff/patch churn. Excellent :) Col -- Colin Guthrie gmane(at)colin.guthr.ie http://colin.guthr.ie/ Day Job: Tribalogic Limited [http://www.tribalogic.net/] Open Source: Mandriva Linux Contributor [http://www.mandriva.com/] PulseAudio Hacker [http://www.pulseaudio.org/] Trac Hacker [http://trac.edgewall.org/] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array
Colin Guthrie wrote: 'Twas brillig, and Jim Lucas at 10/08/09 16:29 did gyre and gimble: $d = array( home_page, member_services, member_services_login, network, resource_center, verse_of_the_day_activate, ); Ahh someone else who always puts a closing , on the end of array definitions to cut down on VCS diff/patch churn. Excellent :) I do it too since it makes life simple when commenting in and out chunks of code. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Brain Freeze
Hello all, I have the follwoing piece of code: //reference a stored procedure $procedure = Execute Procedure informix.arrest_char($part_id); //run the stored procedure $char_query = ifx_query($procedure, $connect_id); //get the result of the stored procedure $char_result = ifx_fetch_row($char_query); //print out the returned values. print_r($char_result); This all works just fine and I have values returned. What I am trying to do is assign one of the array items to a variable. In the past I have done so like this: $stat_1 = $char_result['stat_1']; But for some odd reason $stat_1 doesn't contain anything. Am I going crazy or am I doing something wrong? Thanks, Dan Please disregard...the brain freeze went away and i spotted the problem. The array value name had a [ in it. So when referencing it to assignmy variable I wasn't including the additional bracket. :) Dan
Re: [PHP] Re: array recursion from database rows
On Saturday 24 May 2008, Chris W wrote: Bob wrote: Hi. I have a database table I have created for navigation. The table fields are uid, parent_id, menu_name. Each entry is either a top level element with a parent_id of 0 or a child which has a parent_id that relates to the parent uid. What I am trying to do is recurse through a set of rows adding the child(ren) of a parent to a multi-dimensional array. Does anyone know how I can do this, I've tried (unsuccessfully) to traverse the rows to create this array but I keep failing miserably. This is probably very easy for the people on this list so I am hoping someone could help me out. I recently wrote a function to do just that. My data structure is a little different than yours. My table is called menuitems and is designed to store menu items for many different menus. But I do use the same ParentID concept you described to link sub menus in. I just call my function recessively. Here is a slightly simplified version of my function. I replaced the standard html tags with [ and ] to avoid stupid email clients trying to encode it as an html message. function PrintMenu($MenuID, $ParentItemID) { $query = SELECT * \n; $query .= FROM `menuitem` \n; $query .= WHERE `MenuID` = '$MenuID' AND `ParentItemID` = '$ParentItemID' \n; $query .= ORDER BY `OrderBy` \n; //print [pre$query[/pre\n; $result = mysql_query($query); QueryErrorLog($result, $query, __FILE__, __LINE__, __FUNCTION__, mysql_error(), mysql_errno(), 1); if(mysql_num_rows($result) 0){ print [ul]\n; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ foreach($row as $TmpVar = $TmpValue){ $$TmpVar = $TmpValue; } print [li][a href='$URL']$Title[/a][/li]\n; PrintMenu($MenuID, $MenuItemID); } print [/ul]\n; } } That's bad, because it will run a variable number of SQL queries. It's better to pull all of the data at once, and then recurse over that data structure. To wit (off the cuff and not tested, using PDO syntax for the database): function print_menu() { $items = array(); $db = db_connection(); $result = $db-query(SELECT menu_id, parent_id, name FROM menu_items ORDER BY name); foreach ($result as $record) { $items[$record-parent_id][$record-menu_id] = $record; } $output = _print_menu($items, 0); return $output; } function _print_menu($items, $parent_id) { $output = ''; if (!empty($items[$parent_id])) { foreach ($items[$parent_id] as $menu_id = $item) { $output .= 'li' . $item-name . _menu_print($items, $menu_id) . '/li'; } } return $output ? ul$output/ul : ''; } That way you run only one SQL query, and by pre-grouping you can reduce your iterations as well. -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array recursion from database rows
Bob wrote: Hi. I have a database table I have created for navigation. The table fields are uid, parent_id, menu_name. Each entry is either a top level element with a parent_id of 0 or a child which has a parent_id that relates to the parent uid. What I am trying to do is recurse through a set of rows adding the child(ren) of a parent to a multi-dimensional array. Does anyone know how I can do this, I've tried (unsuccessfully) to traverse the rows to create this array but I keep failing miserably. This is probably very easy for the people on this list so I am hoping someone could help me out. I recently wrote a function to do just that. My data structure is a little different than yours. My table is called menuitems and is designed to store menu items for many different menus. But I do use the same ParentID concept you described to link sub menus in. I just call my function recessively. Here is a slightly simplified version of my function. I replaced the standard html tags with [ and ] to avoid stupid email clients trying to encode it as an html message. function PrintMenu($MenuID, $ParentItemID) { $query = SELECT * \n; $query .= FROM `menuitem` \n; $query .= WHERE `MenuID` = '$MenuID' AND `ParentItemID` = '$ParentItemID' \n; $query .= ORDER BY `OrderBy` \n; //print [pre$query[/pre\n; $result = mysql_query($query); QueryErrorLog($result, $query, __FILE__, __LINE__, __FUNCTION__, mysql_error(), mysql_errno(), 1); if(mysql_num_rows($result) 0){ print [ul]\n; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ foreach($row as $TmpVar = $TmpValue){ $$TmpVar = $TmpValue; } print [li][a href='$URL']$Title[/a][/li]\n; PrintMenu($MenuID, $MenuItemID); } print [/ul]\n; } } -- Chris W KE5GIX Protect your digital freedom and privacy, eliminate DRM, learn more at http://www.defectivebydesign.org/what_is_drm; Ham Radio Repeater Database. http://hrrdb.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array to Object
Eli wrote: Hi, Having this array: $arr = array( 'my var'='My Value' ); Notice the space in 'my var'. Converted to object: $obj = (object)$arr; How can I access $arr['my var'] in $obj ? -thanks! print $obj-{'my var'}; $obj-{'my var'} = 'My New Value'; print $obj-{'my var'}; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array decleration problem
it happens because you forgot the semi-collon at the end of the previews line. Delta Storm [EMAIL PROTECTED] escreveu na mensagem news:[EMAIL PROTECTED] Hi, I'm new to php and im learning, I haven't encounter any problems till now so please help me? :) the code: (learning arrays...) ?php $flavors=array (banana, cucumber, grape, vanilla) $flavors2 [0] =3; $flavors2 [1]=13; $fruits [red] = system; $fruits [yellow] = server; $fruits [purple] = client; echo $flavors; echo br /; echo $flavors2; echo br /; echo $fruits; ? I get an error message: Parse error: parse error, unexpected T_VARIABLE in C:\Program Files\XAMPP\xampp\htdocs\test_folder\exercise12.php on line 16 I embedded the code into an html document so line 16 is line 6 ($flavors2[0]=3;) I have no idea why is this error showing up i tried everything Thank you in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array decleration problem
There another error in your code in addition to the missing ;, echo() is for strings, not arrays. Also, look up the use of single and double quotes in the php docs. It's a good habit to learn to use the right one early on. Delta Storm wrote: Hi, I'm new to php and im learning, I haven't encounter any problems till now so please help me? :) the code: (learning arrays...) ?php $flavors=array (banana, cucumber, grape, vanilla) $flavors2 [0] =3; $flavors2 [1]=13; $fruits [red] = system; $fruits [yellow] = server; $fruits [purple] = client; echo $flavors; echo br /; echo $flavors2; echo br /; echo $fruits; ? I get an error message: Parse error: parse error, unexpected T_VARIABLE in C:\Program Files\XAMPP\xampp\htdocs\test_folder\exercise12.php on line 16 I embedded the code into an html document so line 16 is line 6 ($flavors2[0]=3;) I have no idea why is this error showing up i tried everything Thank you in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Question
cybermalandro cybermalandro wrote: So, I have an array that looks like this rray(3) { [0]= array(8) { [line]= string(1) 1 [ponbr]= string(5) 34474 [emt]= string(3) yes [qty]= string(1) 5 [price]= string(2) 19 [shipdate]= string(8) 11/06/07 [tracking]= string(17) 1 [approved]= string(4) true } [1]= array(8) { [line]= string(1) 1 [ponbr]= string(5) TEST1 [emt]= string(3) yes [qty]= string(1) 5 [price]= string(2) 19 [shipdate]= string(8) 12/04/06 [tracking]= string(9) 123123123 [approved]= string(4) true } [2]= array(8) { [line]= string(1) 2 [ponbr]= string(5) TEST1 [emt]= string(3) yes [qty]= string(1) 5 [price]= string(2) 12 [shipdate]= string(8) 12/04/06 [tracking]= string(12) 123123123123 [approved]= string(4) true } } I want to see if the array[ponbr] values matched then pick this array and construct another one with the matched arrays so I can get something like this [0]= array(8) { [line]= string(1) 1 [ponbr]= string(5) TEST1 [emt]= string(3) yes [qty]= string(1) 5 [price]= string(2) 19 [shipdate]= string(8) 12/04/06 [tracking]= string(9) 123123123 [approved]= string(4) true } [1]= array(8) { [line]= string(1) 2 [ponbr]= string(5) TEST1 [emt]= string(3) yes [qty]= string(1) 5 [price]= string(2) 12 [shipdate]= string(8) 12/04/06 [tracking]= string(12) 123123123123 [approved]= string(4) true } What is the best way to do this efficiently? Thanks for your input! $resultArray = array(); foreach($array as $key=$val) { if($val['ponbr'] === 'TEST1') { $resultArray[$key] = $val; } } $resultArray will contain the output you specified; pretty quick IMO. - tul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Question
Well I don't want have to specify $val['ponbr'] == 'TEST1' I want to say if ($val['ponbr'] == repeated value) then $resultArray[$key] = $val; In other words I want to go through the array matched the values of ponbr that repeat or are the same so if they match then I put the results in another array. Does this make sense? sorry I have difficulties with arrays still. thnx for your input On 3/29/06, M. Sokolewicz [EMAIL PROTECTED] wrote: cybermalandro cybermalandro wrote: So, I have an array that looks like this rray(3) { [0]= array(8) { [line]= string(1) 1 [ponbr]= string(5) 34474 [emt]= string(3) yes [qty]= string(1) 5 [price]= string(2) 19 [shipdate]= string(8) 11/06/07 [tracking]= string(17) 1 [approved]= string(4) true } [1]= array(8) { [line]= string(1) 1 [ponbr]= string(5) TEST1 [emt]= string(3) yes [qty]= string(1) 5 [price]= string(2) 19 [shipdate]= string(8) 12/04/06 [tracking]= string(9) 123123123 [approved]= string(4) true } [2]= array(8) { [line]= string(1) 2 [ponbr]= string(5) TEST1 [emt]= string(3) yes [qty]= string(1) 5 [price]= string(2) 12 [shipdate]= string(8) 12/04/06 [tracking]= string(12) 123123123123 [approved]= string(4) true } } I want to see if the array[ponbr] values matched then pick this array and construct another one with the matched arrays so I can get something like this [0]= array(8) { [line]= string(1) 1 [ponbr]= string(5) TEST1 [emt]= string(3) yes [qty]= string(1) 5 [price]= string(2) 19 [shipdate]= string(8) 12/04/06 [tracking]= string(9) 123123123 [approved]= string(4) true } [1]= array(8) { [line]= string(1) 2 [ponbr]= string(5) TEST1 [emt]= string(3) yes [qty]= string(1) 5 [price]= string(2) 12 [shipdate]= string(8) 12/04/06 [tracking]= string(12) 123123123123 [approved]= string(4) true } What is the best way to do this efficiently? Thanks for your input! $resultArray = array(); foreach($array as $key=$val) { if($val['ponbr'] === 'TEST1') { $resultArray[$key] = $val; } } $resultArray will contain the output you specified; pretty quick IMO. - tul
[PHP] Re: Array Question again
cybermalandro cybermalandro wrote: Let me try this again. I want to take an array that may look like this Opening new Threads over and over don't do any good. Please stick to your opened thread about that issue please. Greets Barry -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array variables with or without quotes
2dogs wrote: I recently encountered a situation where I had to retrieve data from a MYSQL database table with a field named include. My code looked like this: $content_result = mysql_query('SELECT * FROM calander') or die(mysql_error()); $content_row = mysql_fetch_array($content_result); if ($content_row[include]) {go do something;} When I tried to run this, PHP treated the word -include- as a control structure rather than an index name. Understandable. So, I put it in single quotes ('include') to see what would happen and it works fine. But I don't understand why! What is the difference between $content_row [include] and $content_row['include']? I have been unable to resolve this question in the php manual, I need enlightenment. 2dogs http://www.php.net/manual/en/language.types.array.php#language.types.array.foo-bar -- * Chuck Anderson • Boulder, CO http://www.CycleTourist.com Integrity is obvious. The lack of it is common. * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: array variables with or without quotes
I believe it is because without the quotes, it is expecting a predefined constant. With the quotes, it is expecting an array key. This is why if you use a word that is not defined as a constant, php will first look for it as a constant, won't find it, then looks through the array treating it like a key. If it is found as a constant, then the constant's value is used as the key. Jason -Original Message- From: Chuck Anderson [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 22, 2006 3:30 PM To: php-general@lists.php.net Subject: [PHP] Re: array variables with or without quotes 2dogs wrote: I recently encountered a situation where I had to retrieve data from a MYSQL database table with a field named include. My code looked like this: $content_result = mysql_query('SELECT * FROM calander') or die(mysql_error()); $content_row = mysql_fetch_array($content_result); if ($content_row[include]) {go do something;} When I tried to run this, PHP treated the word -include- as a control structure rather than an index name. Understandable. So, I put it in single quotes ('include') to see what would happen and it works fine. But I don't understand why! What is the difference between $content_row [include] and $content_row['include']? I have been unable to resolve this question in the php manual, I need enlightenment. 2dogs http://www.php.net/manual/en/language.types.array.php#language.types.array.f oo-bar -- * Chuck Anderson . Boulder, CO http://www.CycleTourist.com Integrity is obvious. The lack of it is common. * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php smime.p7s Description: S/MIME cryptographic signature
[PHP] Re: array variables with or without quotes
Chuck, you are the man! I decided to reread the manual word for word but have only gotten through Strings as of last night. Thanks for zeroing me in on the right spot. txs 2dogs Chuck Anderson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] 2dogs wrote: I recently encountered a situation where I had to retrieve data from a MYSQL database table with a field named include. My code looked like this: $content_result = mysql_query('SELECT * FROM calander') or die(mysql_error()); $content_row = mysql_fetch_array($content_result); if ($content_row[include]) {go do something;} When I tried to run this, PHP treated the word -include- as a control structure rather than an index name. Understandable. So, I put it in single quotes ('include') to see what would happen and it works fine. But I don't understand why! What is the difference between $content_row [include] and $content_row['include']? I have been unable to resolve this question in the php manual, I need enlightenment. 2dogs http://www.php.net/manual/en/language.types.array.php#language.types.array.foo-bar -- * Chuck Anderson Boulder, CO http://www.CycleTourist.com Integrity is obvious. The lack of it is common. * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array sizes?
Anders Norrbring wrote: Maybe I'm just blind, but I can't find any way to count an array size in bytes? I have a quite big array with multiple data formats in it, and I would like to know how big it is in bytes... I don't think a function exists, but i would probably use (for benchmarking) a recursive foreach in combination with strlen. And add it all up. (This is probably some work for the PC so that's why benchmarking) Anyo other ideas would be cool, since i think i will need that someday too :P Barry -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array sizes?
Anders Norrbring wrote: Maybe I'm just blind, but I can't find any way to count an array size in bytes? I have a quite big array with multiple data formats in it, and I would like to know how big it is in bytes... At 01:05 AM 2/8/2006, Barry wrote: I don't think a function exists, but i would probably use (for benchmarking) a recursive foreach in combination with strlen. And add it all up. (This is probably some work for the PC so that's why benchmarking) It would be interesting to know whether that method was faster or slower than using this: $iLen = strlen(implode(, $aArray)); Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array sizes?
Paul Novitski wrote: Anders Norrbring wrote: Maybe I'm just blind, but I can't find any way to count an array size in bytes? I have a quite big array with multiple data formats in it, and I would like to know how big it is in bytes... At 01:05 AM 2/8/2006, Barry wrote: I don't think a function exists, but i would probably use (for benchmarking) a recursive foreach in combination with strlen. And add it all up. (This is probably some work for the PC so that's why benchmarking) It would be interesting to know whether that method was faster or slower than using this: $iLen = strlen(implode(, $aArray)); Paul At least less memory using. Since foreach sets pointers and reads only array fields and not the whole array. Your example would pump the whole array in one var. But yeah, would be fun to know. you can use microtime to benchmark that. Please use it :) barry -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array sizes?
At 01:05 AM 2/8/2006, Barry wrote: I don't think a function exists, but i would probably use (for benchmarking) a recursive foreach in combination with strlen. And add it all up. (This is probably some work for the PC so that's why benchmarking) It would be interesting to know whether that method was faster or slower than using this: $iLen = strlen(implode(, $aArray)); the problem I would have with the above code would be that it assumes you're using a single dimention array. Recursive foreach: function array_size($a){ $size = 0; while(list($k, $v) = each($a)){ $size += is_array($v) ? array_size($v) : strlen($v); } return $size; } This could possibly be optimised even more by using references or something like that. eg foreach(array_keys($a) as $k){ size = is_array($a[$k]) = array_size($a[$k]) : strlen($a[$k]) But I think that for the most part your time programming will be more important than the programs time running.
Re: [PHP] Re: Array sizes?
Rory Browne skrev: At 01:05 AM 2/8/2006, Barry wrote: I don't think a function exists, but i would probably use (for benchmarking) a recursive foreach in combination with strlen. And add it all up. (This is probably some work for the PC so that's why benchmarking) It would be interesting to know whether that method was faster or slower than using this: $iLen = strlen(implode(, $aArray)); the problem I would have with the above code would be that it assumes you're using a single dimention array. Recursive foreach: function array_size($a){ $size = 0; while(list($k, $v) = each($a)){ $size += is_array($v) ? array_size($v) : strlen($v); } return $size; } This could possibly be optimised even more by using references or something like that. eg foreach(array_keys($a) as $k){ size = is_array($a[$k]) = array_size($a[$k]) : strlen($a[$k]) But I think that for the most part your time programming will be more important than the programs time running. Exactly what I was looking for.. :) Thanks! I personally don't need this at runtime, only at design time, just to help setting limits etc for the running app when testing. -- Anders Norrbring Norrbring Consulting -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array of checkbox values
Interesting way to solve the problem. I thought about checking whether the keys are present (if not the checkbox is set to N.) I wil definitily try this option as well. Thxs all! Sjef Al [EMAIL PROTECTED] schreef in bericht news:[EMAIL PROTECTED] Sjef Janssen wrote: Hallo, I have a form with a number of checkboxes grouped together. The value of these boxes is stored in an array: $used[]. Now I found that the value of checked boxes (value = 'Y') are stored in the array while non checked boxes are not stored at all. This makes the array incomplete as I want to have all checkbox values in the array. For example: for 4 checkboxes the values are checkbox 1: array index = 0 value = Y checkbox 2: array index = 1 value = Y checkbox 3: value = N : it does not occur in the array checkbox 4: array index = 2 value = Y Is there a way to, as it were, complete the array and have all values stored, even the N values? So that array index 2 has a value of N, and array index 3 is Y. Thxs Sjef Seems like I recall solving this problem. It's been a long time, so you'll need to try it. For each checkbox set these two input type=hidden name=foo value=noinput type=checkbox name=foo value=yes You'll get $_POST[foo] as no or yes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array of checkbox values
Sjef Janssen wrote: I have a form with a number of checkboxes grouped together. The value of these boxes is stored in an array: $used[]. Now I found that the value of checked boxes (value = 'Y') are stored in the array while non checked boxes are not stored at all. This makes the array incomplete as I want to have all checkbox values in the array. That's how HTML forms work. The general solution is to set the value of the checkbox to describe what the checkbox is (for example, the row id of the database record that the checkbox is associated with). Then you can loop through and see which values were submitted. -- David Dorward http://blog.dorward.me.uk/ http://dorward.me.uk/ Home is where the ~/.bashrc is -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array of checkbox values
Would it be enough to set a key for each checkbox, for example explicitly say: checkbox[1] checkbox[2] checkbox[3] then a non checked box will have an empty string as a value, whereas the checked ones will have a value of 'Y'. Sjef David Dorward [EMAIL PROTECTED] schreef in bericht news:[EMAIL PROTECTED] Sjef Janssen wrote: I have a form with a number of checkboxes grouped together. The value of these boxes is stored in an array: $used[]. Now I found that the value of checked boxes (value = 'Y') are stored in the array while non checked boxes are not stored at all. This makes the array incomplete as I want to have all checkbox values in the array. That's how HTML forms work. The general solution is to set the value of the checkbox to describe what the checkbox is (for example, the row id of the database record that the checkbox is associated with). Then you can loop through and see which values were submitted. -- David Dorward http://blog.dorward.me.uk/ http://dorward.me.uk/ Home is where the ~/.bashrc is -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: array of checkbox values
Would it be enough to set a key for each checkbox, for example explicitly say: checkbox[1] checkbox[2] checkbox[3] then a non checked box will have an empty string as a value, whereas the checked ones will have a value of 'Y'. Nope. That's the problem. If a checkbox is unchecked the browser doesn't need to send it all when it submits the server... an example: http://www.pjkh.com/~philip/test/check.php Sjef David Dorward [EMAIL PROTECTED] schreef in bericht news:[EMAIL PROTECTED] Sjef Janssen wrote: I have a form with a number of checkboxes grouped together. The value of these boxes is stored in an array: $used[]. Now I found that the value of checked boxes (value = 'Y') are stored in the array while non checked boxes are not stored at all. This makes the array incomplete as I want to have all checkbox values in the array. That's how HTML forms work. The general solution is to set the value of the checkbox to describe what the checkbox is (for example, the row id of the database record that the checkbox is associated with). Then you can loop through and see which values were submitted. -- David Dorward http://blog.dorward.me.uk/ http://dorward.me.uk/ Home is where the ~/.bashrc is -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array of checkbox values
Do something like: $checkboxes = array('food','drink','smoking'); // display the checkboxes foreach($checkboxes as $checkbox) { echo $checkbox: input type=checkbox name=\$checkbox\ /; } Then when processing the form input check if each of the $checkboxes array values are present, if not, you can set to something else such as N, like so. $sent_data = array(); foreach($checkboxes as $checkbox) { if(isset($_REQUEST[$checkbox])) { $sent_data[$checkbox] = 'Y'; } else { $sent_data[$checkbox] = 'N'; } } James Sjef Janssen wrote: Hallo, I have a form with a number of checkboxes grouped together. The value of these boxes is stored in an array: $used[]. Now I found that the value of checked boxes (value = 'Y') are stored in the array while non checked boxes are not stored at all. This makes the array incomplete as I want to have all checkbox values in the array. For example: for 4 checkboxes the values are checkbox 1: array index = 0 value = Y checkbox 2: array index = 1 value = Y checkbox 3: value = N : it does not occur in the array checkbox 4: array index = 2 value = Y Is there a way to, as it were, complete the array and have all values stored, even the N values? So that array index 2 has a value of N, and array index 3 is Y. Thxs Sjef -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array of checkbox values
Sjef Janssen wrote: Hallo, I have a form with a number of checkboxes grouped together. The value of these boxes is stored in an array: $used[]. Now I found that the value of checked boxes (value = 'Y') are stored in the array while non checked boxes are not stored at all. This makes the array incomplete as I want to have all checkbox values in the array. For example: for 4 checkboxes the values are checkbox 1: array index = 0 value = Y checkbox 2: array index = 1 value = Y checkbox 3: value = N : it does not occur in the array checkbox 4: array index = 2 value = Y Is there a way to, as it were, complete the array and have all values stored, even the N values? So that array index 2 has a value of N, and array index 3 is Y. Thxs Sjef Seems like I recall solving this problem. It's been a long time, so you'll need to try it. For each checkbox set these two input type=hidden name=foo value=noinput type=checkbox name=foo value=yes You'll get $_POST[foo] as no or yes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: array carrying from one php page to another
On 08 December 2005 16:47, Sandy Keathley wrote: I have an array $journal that I want to carry from a page (where it was created) to another page (a popup that shows the variables contents). Is this automatically available? or do I have to do something special to php?? One way: $serArray = serialize($array); input type=hidden name=serArray value=?php echo $serArray ? At other end: $array = unserialize($_POST['serArray']); == OR session_start(); . . . $_SESSION['array'] = serialize($array); Why on earth would you want to serialize an array you're adding to the session? That's just a terrible waste of good machine cycles. Zend Certified Engineer Really?? I think I just lost all faith in that qualification. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: array carrying from one php page to another
Ford, Mike wrote: On 08 December 2005 16:47, Sandy Keathley wrote: ... . . $_SESSION['array'] = serialize($array); Why on earth would you want to serialize an array you're adding to the session? That's just a terrible waste of good machine cycles. sarcasmterrible, very. too many hits to the server and this little faux pas will really bring the CPU to its knees/sarcasm Sandy, anything you stick in $_SESSION is automatically serialized by php when the session is closed (or the request is complete - i.e. during script shutdown) .. which means you don't have to do it! Zend Certified Engineer Really?? I think I just lost all faith in that qualification. state provided 'educational' services are nothing more than highly sophisticated indoctrination systems ... Zend is upfront about the reasons for having a 'qualification' system but is Leeds Met? Or lets look at that a totally different way ... Leeds Met is a very prejudiced, dogmatic operation with a higgly judgemental cultural background that is incapable of stimulating or encouraging open-minded, critical thinking. I know this because you work there and you one comment about losing faith tells me everything there is to know about Leeds Met and all the people who work/study there; just like you are able to judge the Zend Exam based on one slight mistake from one particular person who advertises herself as having passed said exam overout Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array carrying from one php page to another
I have an array $journal that I want to carry from a page (where it was created) to another page (a popup that shows the variables contents). Is this automatically available? or do I have to do something special to php?? One way: $serArray = serialize($array); input type=hidden name=serArray value=?php echo $serArray ? At other end: $array = unserialize($_POST['serArray']); == OR session_start(); . . . $_SESSION['array'] = serialize($array); At other end: $array = unserialize($_SESSION['array']); If you change or repopulate the array, use the same session name, or, to be safe, $_SESSION['array'] = null; before repopulating the session. Make sure session_start() is on every page that needs access to the session variable, including the popup. SK WebDesigns Internet Consulting E-commerce Solutions Application Development Sandy Keathley Zend Certified Engineer [EMAIL PROTECTED] 972-569-8464 http://www.KeathleyWebs.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array woes
Within grabQuotes(); if you do a var_dump($arg); (where $arg is $res[id]) is your vehicle name displayed? If it is, and you're using it correctly, make sure you're returning the value you'd like correctly. It might help to post your grabQuotes function as well as the code that displays $cars[]. Matt blackwater dev [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hello all, I have some array code driving me nuts. I am pulling from a db: select id, vehicle, has_quotes from cars where active=1 I then loop through these and build an array that contains the id's and cars. while($res){ $cars[$res[id]]=$res[vehicle]; //here is the problem, when has_quotes is 1, I call another function to grab the quotes if ($res[has_quotes]1){ $cars[$res[id]]=grabQuotes($res[id]); } } The grabQuotes function returns an array and works fine. THe problem is when I go to display these, I cycle through the car array printing id and vehicle name. I do a check so if vehicle name is an array, I print out the quotes from the inner array, problem is I have lost the vehicle name! How can I fix this? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array within array
I would do something like $fp = fopen($file_location, 'r'); while (!$fp) { $csv_line = fgetcsv($fp); //insert line into database here after appropriate validation and cleaning } On Fri, 30 Sep 2005 06:29:11 -0400, Chris [EMAIL PROTECTED] wrote: Greetings PHP community, I have a CSV text file which I need to use to update existing DB records. So I have the following : $array_file = file(path/to/file); file() creates an array comprising each line of the file, but if each line contains 20 or so CS values, how do I go about reading each line and updating the db. Pseudo code : = $array_file = file(path/to/file); while (explode(',',$file_array)) { do update on db for each line of array } = Any pointers ? -- Chris Blake Cell: 082 775 1492 Work: +27 11 880 2825 Fax : +27 11 782 0841 Mail: [EMAIL PROTECTED] Immortality -- a fate worse than death. -- Edgar A. Shoaff -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array: If i'm in the child array then how I tell the parent's key name..
Let me reply with a question first :) how do you get *to* the child? ;) post some code so we know. In 99.99% of the cases, the way you get to the child includes a way to find out the parent key (usually you foreach() to it, or something similair). - tul Scott Fletcher wrote: Suppose that I'm in a child array and I wanna know how do I tell what key is the parent's level, one level up... For example, --snip-- $arr['ABC']['DEF']; --snip-- Let's say the child is DEF then the key name one level up would be ABC. How do I determine the one level up? Thanks... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Select from database
Array ( [count] = 1 [0] = Array ( [clientaccountmanager] = Array ( [count] = 2 [0] = 210 [1] = 149 ) I've got the following Query=select * from client WHERE clientaccountmanager='$value of array1' OR '$2nd value of array 1' So that the query loops through the whole array... - No indenting for some reason, sorry You should construct your query like this: SELECT x FROM y where Z IN (value1,value2,value3) For looping on arrays, have a look at foreach: http://uk2.php.net/manual/en/control-structures.foreach.php Hope this helps Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array merge problem
could this help If you want to completely preserve the arrays and just want to append them to each other, use the + operator: ?php $array1 = array(); $array2 = array(1 = data); $result = $array1 + $array2; ? http://www.php.net/manual/en/function.array-merge.php Ahmed Abdel-Aliem wrote: i have the array with the following structure : Array ( [19] = 20.00 [25] = 20.00 [7] = 30.00 [17] = 30.00 ) when i merge a field to it using array_merge it returns that : Array ( [0] = 20.00 [1] = 20.00 [2] = 30.00 [3] = 30.00 [4] = 200.00 ) how can i merge the field without losing the original keys ? can anyone help me with that plz thanks in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array diff with both values returned
http://uk2.php.net/manual/en/function.array-diff.php http://uk2.php.net/manual/en/function.array-diff-assoc.php Blackwater Dev wrote: Hello, Is there a good way to get the difference in two arrays and have both values returned? I know I can use array_dif to see what is in one and not the other but...I need it to work a bit differently. I have: $array1=array(name=fred,gender=m,phone==555-); $array2=array(name=fred,gender=f,phone==555-); I want to compare these two and have it return: array(gender=array(m,f)); I want it to return all of the differences with the key and then the value from array 1 and 2. How? Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array from folder
* Ed Dorsch [EMAIL PROTECTED]: Can PHP generate an array based on file names in a folder? For example, if I have a folder called photos that includes three files -- tree.jpg, house.jpg and boat.jpg -- can PHP look at the file and generate a variable $photos = array (tree, house,boat). Any ideas for how to sniff out a folder to determine how many files are in it and then create an array with the file names in it? You might want to try PEAR's File_Find package. With it, you could pass a pattern to match, and receive an array of files that match. You could then use array_map() to strip the suffix: include_once 'File/Find.php'; function photo_basename($file) { list($name, $sfx) = explode('.', basename($file), 2); return $name; } $photos = File_Find::glob('/.*\.(jpg|png|gif)$/i', 'photos', 'perl'); $photos = array_map('photo_basename', $photos); To determine the number of files, simply do a count() on the $photos array. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array search
Malcolm wrote: Hello All, I've been trying for days now to make this work. I'm trying to search my array for a value and return the key. I get the visitor's IP and try this -- this is the latest, I've tried a few functions to echo the name associated with the viz_ip. $viz_ip= $_SERVER['REMOTE_ADDR']; $byte_ip= array( 204.126.202.56=Mark, 63.230.76.166=Bob, 63.220.76.165=John, ); function _array_search ($viz_ip, $byte_ip) { foreach($byte_ip as $key = $val) { if ($viz_ip === $key) { return($val); } } return(False); } I'm no wiz but this shouldn't be this hard, maybe I'm thinking wrong. I've read the examples at php.net but I just can't get it. Some help or even a hint ? best regards, malcolm I might be the only one to notice here, but you don't want to find the KEY, you want to find the VALUE. Otherwise, you'll need to assemble your array differently. $viz_ip= $_SERVER['REMOTE_ADDR']; $byte_ip= array( 204.126.202.56=Mark, 63.230.76.166=Bob, 63.220.76.165=John ); That means: $byte_ip[$viz_ip] = some_name; That's because you have ips set as your *keys*, and not your values. To do what you wanted, simply either: a) reverse the array, making keys values and values keys: $byte_ip= array( Mark=204.126.202.56, Bob=63.230.76.166, John=63.220.76.165 ); or: b) change the function to match on key (for which you don't *need* a function). - Tul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array search
Ah so -- array_search only works on values ? That probably accounts for my first day or so, thanks. I've got it now. On Sun, 23 Jan 2005 19:22:32 +0100, M. Sokolewicz [EMAIL PROTECTED] wrote: Malcolm wrote: Hello All, I've been trying for days now to make this work. I'm trying to search my array for a value and return the key. I get the visitor's IP and try this -- this is the latest, I've tried a few functions to echo the name associated with the viz_ip. $viz_ip= $_SERVER['REMOTE_ADDR']; $byte_ip= array( 204.126.202.56=Mark, 63.230.76.166=Bob, 63.220.76.165=John, ); function _array_search ($viz_ip, $byte_ip) { foreach($byte_ip as $key = $val) { if ($viz_ip === $key) { return($val); } } return(False); } I'm no wiz but this shouldn't be this hard, maybe I'm thinking wrong. I've read the examples at php.net but I just can't get it. Some help or even a hint ? best regards, malcolm I might be the only one to notice here, but you don't want to find the KEY, you want to find the VALUE. Otherwise, you'll need to assemble your array differently. $viz_ip= $_SERVER['REMOTE_ADDR']; $byte_ip= array( 204.126.202.56=Mark, 63.230.76.166=Bob, 63.220.76.165=John ); That means: $byte_ip[$viz_ip] = some_name; That's because you have ips set as your *keys*, and not your values. To do what you wanted, simply either: a) reverse the array, making keys values and values keys: $byte_ip= array( Mark=204.126.202.56, Bob=63.230.76.166, John=63.220.76.165 ); or: b) change the function to match on key (for which you don't *need* a function). - Tul -- O -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array walk and class member functions
Tom wrote: Hi I'm batting my head against a wall on this one... I have a class that has a constructor which sets some initial conditions, and then a public function that does some work. I want to be able to call this function from an external array_walk call, but when I try and reference it as $myClass-myFunction in the array_walk call, I get an error back saying that this is an invalid function. Allow Monty Python to help you. ?php class aClass { function aMemberFunction($value, $key, $stuff) { print_r($key: $value. $stuff!\n); } } $myArray = array(item1=firstItem, item2=secondItem); $myClass = new aClass; $stuff = Your father was a hamster, and your mother smelled of Elderberries!; array_walk($myArray, array($myClass, 'aMemberFunction'), $stuff); ? -- Teach a person to fish... Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html PHP Manual: http://www.php.net/manual/en/index.php php-general archives: http://marc.theaimsgroup.com/?l=php-generalw=2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array unset
Bruno b b magalhães wrote: The problem is that when I delete an specific array, it outputs something like this: ( [0] = Array ( [moduleId] = 4 [moduleName] = Contents [modulePath] = contents [moduleAliasPath] = [moduleController] = administration [moduleLevel] = 5 [moduleOrder] = 0 [moduleVisibility] = 1 [moduleType] = none [moduleStatus] = 1 ) [2] = Array ( [moduleId] = 1 [moduleName] = System [modulePath] = system [moduleAliasPath] = [moduleController] = administration [moduleLevel] = 5 [moduleOrder] = 2 [moduleVisibility] = 1 [moduleType] = default [moduleStatus] = 1 ) [3] = Array ( [moduleId] = 2 [moduleName] = Logout [modulePath] = logout [moduleAliasPath] = [moduleController] = administration [moduleLevel] = 5 [moduleOrder] = 3 [moduleVisibility] = 1 [moduleType] = alias [moduleStatus] = 1 ) ) So, the question, how resort the numeric values to 1,2,3,4? which numeric values ? -- Sebastian Mendel www.sebastianmendel.de www.warzonez.de www.tekkno4u.de www.nofetish.com www.sf.net/projects/phpdatetimewww.sf.net/projects/phptimesheet -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array unset
Bruno b b magalhães wrote: So, the question, how resort the numeric values to 1,2,3,4? http://www.php.net/array_values Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array to $_GET variable
Mike Smith wrote: I am trying to cache a database recordset so users can sort, etc without hitting the database everytime. I'm using ADODB to access a MSSQL database. $s = SELECT id, part, description FROM parts\n; $r = $db-Execute($s); $parts = array(id=array(),part=array(),desc=array()) while(!$r-EOF){ array_push($parts['id'],$r-fields[0]); array_push($parts['part'],$r-fields[0]); array_push($parts['desc'],$r-fields[0]); $r-MoveNext(); } // print_r($parts) displays array data. Here's what I'm doing: $v = serialize($parts); echo a href=\{$_SERVER['PHP_SELF']}?getvar=$v\Link/a\n; If($_GET['getvar']){ $newvar = unserialize($_GET['getvar']); //This does nothing echo $newvar; print_r($newvar); } Am i missing something very simple? Should I make the array a $_SESSION variable, or how do others cache a recordset? i would prefer $_SESSION! btw. - do you see the ...?getvar=... in the URL ? - what does var_dump( $_GET['getvar'] ); - do you tried urlencode(); -- Sebastian Mendel www.sebastianmendel.de www.warzonez.de www.tekkno4u.de www.nofetish.com www.sf.net/projects/phpdatetimewww.sf.net/projects/phptimesheet -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array Losing value
if I die(sizeof($objDBI-Fetch_Array($objDBI-getResultID( within the DBI method, it return the correct value, however if I do $retval = $objDBI-Fetch_Array($objDBI-getResultID()); die(sizeof($retVal)); $retval != $retVal -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php that was a typo... the real code has both $retVal -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array Losing value
nevermind, I found a work around for it... I still would like to know why the value is lost. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array Losing value
On Tue, 20 Jul 2004 10:50:04 -0500 (CDT), Jonathan Villa [EMAIL PROTECTED] wrote: nevermind, I found a work around for it... I still would like to know why the value is lost. What's the work-around? -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Losing value
if I die(sizeof($objDBI-Fetch_Array($objDBI-getResultID( within the DBI method, it return the correct value, however if I do $retval = $objDBI-Fetch_Array($objDBI-getResultID()); die(sizeof($retVal)); $retval != $retVal -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array indexes as arguments to a function
I don't understand what you're asking. If you want to return a portion of an array, simple return the element holding it. In your example: POST[var1_arr][dim1][dim2] return var1_arr; Will return whatever lives in var1_arr. Have a play around, you can see what a variable contains using print_r() Dennis Gearon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] please CC me, as I am on digest. --- say I've got a class that stores the cookie/get/post vars. I want to retrieve say one of them. Say, that post vars come back from browser as: POST[var1_arr][dim1][dim2] they are stored in object-post_vars[var1_arr][dim1][dim2]; object-post_vars[singleton]; I have the function class-get_post_var($index_arr){ return correct, processed post var; } How can I get the function to return an arbitrary depth into the post vars array? i.e. EITHER return $this-class_user_input_processing_function( $this-post_vars, $index_arr); Where $index_arr contains either: $index_arr = array(var1_arr,dim1_value, dim2_value); -or- $index_arr = array(singleton); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array Sorting Headaches
Torsten Roehr wrote: Burhan Khalid [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Greetings everyone : Having a hard time with this one. I have a multi-dim array $foo[$x][$y]['key'], where $x and $y are numeric. Here is some sample data [ snipped ] I need to filter the results so that I get the latest expiry date for each product. The expires field actually contains a timestamp. So for the sample array above, the resultant array would have only keys 0 and 2, filtering out all the rest. There are around 180+ main entries, with any number of sub entries, but each sub entry has the same four keys. Any ideas? Getting a rather large headache mulling over this. Hi, as your structure is always the same you could just loop through all elements and subelements and use unset() to remove the unwanted array elements: foreach ($foo as $key = $value) { foreach ($value as $subkey = $subvalue) { // put your check logic here if ($foo[$key][$subkey]['expires'] == '') { unset($foo[$key][$subkey]); } } } What do you think? Well this is what I have right now, but the problem is the logic which checks to see for each domain which is the last expired date. I have three nested for loops right now, and not getting anywhere :( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array Sorting Headaches
Burhan Khalid [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Torsten Roehr wrote: Burhan Khalid [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Greetings everyone : Having a hard time with this one. I have a multi-dim array $foo[$x][$y]['key'], where $x and $y are numeric. Here is some sample data [ snipped ] I need to filter the results so that I get the latest expiry date for each product. The expires field actually contains a timestamp. So for the sample array above, the resultant array would have only keys 0 and 2, filtering out all the rest. There are around 180+ main entries, with any number of sub entries, but each sub entry has the same four keys. Any ideas? Getting a rather large headache mulling over this. Hi, as your structure is always the same you could just loop through all elements and subelements and use unset() to remove the unwanted array elements: foreach ($foo as $key = $value) { foreach ($value as $subkey = $subvalue) { // put your check logic here if ($foo[$key][$subkey]['expires'] == '') { unset($foo[$key][$subkey]); } } } What do you think? Well this is what I have right now, but the problem is the logic which checks to see for each domain which is the last expired date. I have three nested for loops right now, and not getting anywhere :( Maybe it works if you put the expires value in a seperate array, sort it and then you can get the key of the first one and use unset(): foreach ($foo as $key = $value) { $tempArray = array(); foreach ($value as $subkey = $subvalue) { // add expires value only to the temporary array for sorting $tempArray[$subkey] = $foo[$key][$subkey]['expires']; } // sort array by value descending arsort($tempArray); // get first (and therefore highest timestamp) key/value pair $firstEntry = each($tempArray); $notneededSubkey = $firstEntry['key']; // now unset the array value with the not needed subkey unset($foo[$key][$notneededSubkey]); } Have not tried it but may work. Hope you see my point. Regards, Torsten Roehr -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array Sorting Headaches
Torsten Roehr wrote: Burhan Khalid [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Torsten Roehr wrote: Burhan Khalid [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Greetings everyone : Having a hard time with this one. I have a multi-dim array $foo[$x][$y]['key'], where $x and $y are numeric. Here is some sample data [ snipped ] I need to filter the results so that I get the latest expiry date for each product. The expires field actually contains a timestamp. So for the sample array above, the resultant array would have only keys 0 and 2, filtering out all the rest. There are around 180+ main entries, with any number of sub entries, but each sub entry has the same four keys. Any ideas? Getting a rather large headache mulling over this. Hi, as your structure is always the same you could just loop through all elements and subelements and use unset() to remove the unwanted array elements: foreach ($foo as $key = $value) { foreach ($value as $subkey = $subvalue) { // put your check logic here if ($foo[$key][$subkey]['expires'] == '') { unset($foo[$key][$subkey]); } } } What do you think? Well this is what I have right now, but the problem is the logic which checks to see for each domain which is the last expired date. I have three nested for loops right now, and not getting anywhere :( Maybe it works if you put the expires value in a seperate array, sort it and then you can get the key of the first one and use unset(): foreach ($foo as $key = $value) { $tempArray = array(); foreach ($value as $subkey = $subvalue) { // add expires value only to the temporary array for sorting $tempArray[$subkey] = $foo[$key][$subkey]['expires']; } // sort array by value descending arsort($tempArray); // get first (and therefore highest timestamp) key/value pair $firstEntry = each($tempArray); $notneededSubkey = $firstEntry['key']; // now unset the array value with the not needed subkey unset($foo[$key][$notneededSubkey]); } Have not tried it but may work. Hope you see my point. Well, it does some sorting, but not quite what I'm after :( I've managed to get the list so that all the (sub) entries are sorted in the correct order. Now its just a matter of finding the highest expire date for /each/ domain, and delete the other entries for that domain. So, in the end, all that's left is one entry per domain, with its latest expire date. Hopefully this makes it a bit clearer. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array Sorting Headaches
Well, it does some sorting, but not quite what I'm after :( I've managed to get the list so that all the (sub) entries are sorted in the correct order. Now its just a matter of finding the highest expire date for /each/ domain, and delete the other entries for that domain. So, in the end, all that's left is one entry per domain, with its latest expire date. Hopefully this makes it a bit clearer. OK, so it's just the other way round - I see. Instead of deleting the entry with the highest expiry date we delete all the others: foreach ($foo as $key = $value) { $tempArray = array(); foreach ($value as $subkey = $subvalue) { // add expires value only to the temporary array for sorting $tempArray[$subkey] = $foo[$key][$subkey]['expires']; } // sort array by value descending arsort($tempArray); /* new stuff starts here */ // remove the entry with the latest expiry (the first array element) array_push($tempArray); // now unset all remaining/not needed entries foreach ($tempArray as $tempKey = $tempValue) { unset($foo[$key][$tempKey]); } } By the way, isn't there a way to filter this stuff BEFORE or WHILE the whole array is created? Regards, Torsten -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array Sorting Headaches
Torsten Roehr wrote: Well, it does some sorting, but not quite what I'm after :( I've managed to get the list so that all the (sub) entries are sorted in the correct order. Now its just a matter of finding the highest expire date for /each/ domain, and delete the other entries for that domain. So, in the end, all that's left is one entry per domain, with its latest expire date. Hopefully this makes it a bit clearer. OK, so it's just the other way round - I see. Instead of deleting the entry with the highest expiry date we delete all the others: foreach ($foo as $key = $value) { $tempArray = array(); foreach ($value as $subkey = $subvalue) { // add expires value only to the temporary array for sorting $tempArray[$subkey] = $foo[$key][$subkey]['expires']; } // sort array by value descending arsort($tempArray); /* new stuff starts here */ // remove the entry with the latest expiry (the first array element) array_push($tempArray); // now unset all remaining/not needed entries foreach ($tempArray as $tempKey = $tempValue) { unset($foo[$key][$tempKey]); } } By the way, isn't there a way to filter this stuff BEFORE or WHILE the whole array is created? Thanks for the help. I'll give that snippet a try and see what comes out. The array is a result of a rather nasty SQL statement running against a database (which I didn't design). Unfortunately, the way the database is designed, its very difficult to extract the domain information. I am in the process of rewriting the entire thing as a Java application, hopefully that will make things a bit clearer, since I'll also be refactoring the database schema. Many thanks, Burhan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Array Sorting Headaches
OK, so it's just the other way round - I see. Instead of deleting the entry with the highest expiry date we delete all the others: foreach ($foo as $key = $value) { $tempArray = array(); foreach ($value as $subkey = $subvalue) { // add expires value only to the temporary array for sorting $tempArray[$subkey] = $foo[$key][$subkey]['expires']; } // sort array by value descending arsort($tempArray); /* new stuff starts here */ // remove the entry with the latest expiry (the first array element) array_push($tempArray); // now unset all remaining/not needed entries foreach ($tempArray as $tempKey = $tempValue) { unset($foo[$key][$tempKey]); } } By the way, isn't there a way to filter this stuff BEFORE or WHILE the whole array is created? Thanks for the help. I'll give that snippet a try and see what comes out. The array is a result of a rather nasty SQL statement running against a database (which I didn't design). Unfortunately, the way the database is designed, its very difficult to extract the domain information. I am in the process of rewriting the entire thing as a Java application, hopefully that will make things a bit clearer, since I'll also be refactoring the database schema. Please let me know if it works. I'm sure there's a more elegant way to do it. Many thanks, Burhan You're welcome ;) Torsten -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Sorting Headaches
Burhan Khalid [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Greetings everyone : Having a hard time with this one. I have a multi-dim array $foo[$x][$y]['key'], where $x and $y are numeric. Here is some sample data : Array ( [$x] = Array ( [0] = Array ( [invoiceid] = 11842 [product] = myproduct [domain] = foo.net [expires] = February 28, 2004 ) [1] = Array ( [invoiceid] = 10295 [product] = myotherproduct [domain] = foo.net [expires] = December 9, 2003 ) [2] = Array ( [invoiceid] = 10202 [product] = product1 [domain] = foo.bar [expires] = January 19, 2003 ) [3] = Array ( [invoiceid] = 10005 [product] = product2 [domain] = foo.bar [expires] = December 11, 2002 ) ) ) I need to filter the results so that I get the latest expiry date for each product. The expires field actually contains a timestamp. So for the sample array above, the resultant array would have only keys 0 and 2, filtering out all the rest. There are around 180+ main entries, with any number of sub entries, but each sub entry has the same four keys. Any ideas? Getting a rather large headache mulling over this. Hi, as your structure is always the same you could just loop through all elements and subelements and use unset() to remove the unwanted array elements: foreach ($foo as $key = $value) { foreach ($value as $subkey = $subvalue) { // put your check logic here if ($foo[$key][$subkey]['expires'] == '') { unset($foo[$key][$subkey]); } } } What do you think? Regards, Torsten Roehr Thanks again, Burhan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array data
Think this is what u want Imran Asghar wrote: Hi, Is not working, is it correct way File1.php ? $colors = array('red','blue','green','yellow'); ? form action=file2.php method=post input type=hidden type name=colors value=?=$colors? /fomr ?php $colors = array('red','blue','green','yellow'); ? form action=file2.php method=post ?php foreach $colors as $k = $v { ? input type=hidden type name=colors[?php echo $k; ?] value=?php echo $v; ? ?php } ? /form File2.php ? echo $colors[0]; echo $colors[1]; echo $colors[2]; echo $colors[4]; ? ?php echo $_POST['colors'][0]; etc ? imee -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array data
Hello Imran, On 12 Feb 2004 at 1:17, Imran Asghar wrote: Hi, Is not working, is it correct way File1.php ? $colors = array('red','blue','green','yellow'); ? form action=file2.php method=post input type=hidden type name=colors value=?=$colors? /fomr File2.php ? echo $colors[0]; echo $colors[1]; echo $colors[2]; echo $colors[4]; ? imee I'm afraid you'll have to start learning PHP from scratch. The freely-available PHP manual has a fairly good introductory section and you'll also find tons of tutorials for beginners on the web. Good luck, Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: array block
On Saturday 31 January 2004 11:48, Shawn McKenzie wrote: You would need to give an example of what you mean by change dynamically, because if you can't predict the key indexes then how can you know which ones to use in your anchor tag? foreach ($arr as $key = $value) { echo Key: $key; Value: $valuebr\n; } -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* If your attack is going really well, it's an ambush -- Murphy's Military Laws n47 */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: array block
On Fri, 2004-01-30 at 22:48, Shawn McKenzie wrote: You would need to give an example of what you mean by change dynamically, because if you can't predict the key indexes then how can you know which ones to use in your anchor tag? say this: $menu = array ( 'link1' = array( 'url' = 'foo', 'title' = 'bar' ), 'link2' = array( 'url' = 'foo', 'title' = 'bar' ) ); were to dynamically change to this: $menu = array ( 'link1' = array( 'url' = 'foo', 'title' = 'bar' 'style' = 'dolor' ), 'link2' = array( 'url' = 'foo', 'title' = 'bar' 'style' = 'amet' ) ); I'm stretching here, have no practical use for it, and can think of much better ways to handle it but am still curious. Obviously you need to traverse the inner array which is not an issue, but I get stumped with trying to format it as in the previous examples. -- BrianGnuPG - KeyID: 0x04A4F0DC | URL: www.gfx-design.com/keys Key Server: pgp.mit.edu == gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC GnuPG: http://gnupg.org http://www.biglumber.com/x/web?qs=0x2C35011004A4F0DC Linux Registered User #339825 at http://counter.li.org signature.asc Description: This is a digitally signed message part
RE: [PHP] Re: array block
If you have an array like this (change the url to href): $menu = array ( 'link1' = array( 'url' = 'foo', 'title' = 'bar' 'style' = 'dolor' ), 'link2' = array( 'url' = 'foo', 'title' = 'bar' 'style' = 'amet' ) ); Then something like this, or the general idea should work: $menu = array ( 'link1' = array( 'href' = 'foo', 'title' = 'bar', 'style' = 'dolor' ), 'link2' = array( 'href' = 'foo', 'title' = 'bar', 'style' = 'amet' ) ); foreach ($menu as $array) { $tag = a; foreach ($array as $k = $v) { $tag .= $k=\$v\; } $tag .= $menu/a\n; echo $tag; } There are better ways to do it I'm sure, but this is just following the previous example. -Shawn -Original Message- From: Brian V Bonini [mailto:[EMAIL PROTECTED] Sent: Saturday, January 31, 2004 8:56 AM To: Shawn McKenzie Cc: PHP Lists Subject: Re: [PHP] Re: array block On Fri, 2004-01-30 at 22:48, Shawn McKenzie wrote: You would need to give an example of what you mean by change dynamically, because if you can't predict the key indexes then how can you know which ones to use in your anchor tag? say this: $menu = array ( 'link1' = array( 'url' = 'foo', 'title' = 'bar' ), 'link2' = array( 'url' = 'foo', 'title' = 'bar' ) ); were to dynamically change to this: $menu = array ( 'link1' = array( 'url' = 'foo', 'title' = 'bar' 'style' = 'dolor' ), 'link2' = array( 'url' = 'foo', 'title' = 'bar' 'style' = 'amet' ) ); I'm stretching here, have no practical use for it, and can think of much better ways to handle it but am still curious. Obviously you need to traverse the inner array which is not an issue, but I get stumped with trying to format it as in the previous examples. -- BrianGnuPG - KeyID: 0x04A4F0DC | URL: www.gfx-design.com/keys Key Server: pgp.mit.edu == gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC GnuPG: http://gnupg.org http://www.biglumber.com/x/web?qs=0x2C35011004A4F0DC Linux Registered User #339825 at http://counter.li.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array block
Brian V Bonini wrote: I'm having array block, trying to format the data in a two dimensional associative array. foreach($menu as $k = $v) { etc.. need to end up with a href=url title=titlelink(x)/a Since it's two-dimensional, the $v you're getting is actually an array. So you'll have to iterate through the outer array, $menu, and then do it again for each inner array. As was mentioned before/elsewhere, a for would be more efficient than a foreach unless you actually need a specific key or value. So something like $count = sizeof($menu); for ( i=0; i$count; i++) { foreach( array_shift($menu) as $k = $v ) { //ect. } } It's been a long day; please, someone verify this... :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array block
foreach ($menu as $text = $array) { $url = $array['url']; $title = $array['title']; echo a href=\$url\ title=\$title\$k/a\n; } HTH -Shawn Brian V Bonini [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm having array block, trying to format the data in a two dimensional associative array. $menu = array ( 'link1' = array( 'url' = 'foo', 'title' = 'bar' ), 'link2' = array( 'url' = 'foo', 'title' = 'bar' ) ); foreach($menu as $k = $v) { etc.. need to end up with a href=url title=titlelink(x)/a Can't seem to put this together in my head. Long day I guess. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array block
Sorry, $k should be $text. foreach ($menu as $text = $array) { $url = $array['url']; $title = $array['title']; echo a href=\$url\ title=\$title\$text/a\n; } Shawn McKenzie [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] foreach ($menu as $text = $array) { $url = $array['url']; $title = $array['title']; echo a href=\$url\ title=\$title\$k/a\n; } HTH -Shawn Brian V Bonini [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm having array block, trying to format the data in a two dimensional associative array. $menu = array ( 'link1' = array( 'url' = 'foo', 'title' = 'bar' ), 'link2' = array( 'url' = 'foo', 'title' = 'bar' ) ); foreach($menu as $k = $v) { etc.. need to end up with a href=url title=titlelink(x)/a Can't seem to put this together in my head. Long day I guess. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: array block
On Fri, 2004-01-30 at 18:47, Shawn McKenzie wrote: Sorry, $k should be $text. foreach ($menu as $text = $array) { $url = $array['url']; $title = $array['title']; echo a href=\$url\ title=\$title\$text/a\n; } Gotcha, thanks! That'll work for this but for arguments sake what if the inner array were to change dynamically? -- BrianGnuPG - KeyID: 0x04A4F0DC | URL: www.gfx-design.com/keys Key Server: pgp.mit.edu == gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC GnuPG: http://gnupg.org http://www.biglumber.com/x/web?qs=0x2C35011004A4F0DC Linux Registered User #339825 at http://counter.li.org signature.asc Description: This is a digitally signed message part
Re: [PHP] Re: array block
You would need to give an example of what you mean by change dynamically, because if you can't predict the key indexes then how can you know which ones to use in your anchor tag? -Shawn Brian V Bonini [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Key Test
Cameron B. Prince wrote: Hi, How would I go about determining if a specific key exists in an array? I want to see if $conf['hOpt'] is defined. is_array only works at the $conf level. You want: if(isset($conf['hOpt'])) { ... } You should always use isset to check if a variable is set, whether it is a straight variable, an array index, or an object member. -- paperCrane Justin Patrin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array data to XML
Of course. If it's a simple (short) array, you can just create a string with the XML tags and array values, and write that to a file with an XML extension. More sexy would be to use the DOMXML functions in PHP. http://us3.php.net/manual/en/ref.domxml.php Guy named Kris wrote a great XML - PHP script that you can find here, although it may be more than you are looking for: http://www.devdump.com/phpxml.php I've written a DOMXML-based PHP - XML function that takes Kris' structure as input, if you're interested. -- Matt Grimm Web Developer The Health TV Channel, Inc. (a non - profit organization) 3820 Lake Otis Parkway Anchorage, AK 99508 907.770.6200 ext. 686 907.336.6205 (fax) E-mail: [EMAIL PROTECTED] Web: www.healthtvchannel.org Chakravarthy Cuddapah [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] newbie ... Is it possible to format data in array to XML and display ? Thanks ! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array data to XML
Hello, On 12/24/2003 02:44 PM, Chakravarthy Cuddapah wrote: Is it possible to format data in array to XML and display ? This class seems to do what you want. It requires DOM XML extension. Class: XML Array http://www.phpclasses.org/xmlarray You may also want to try this class for generating XML documents without requiring any extension: Class: XML Writer class http://www.phpclasses.org/xmlwriter -- Regards, Manuel Lemos Free ready to use OOP components written in PHP http://www.phpclasses.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array -- If
Hi Jason, perhaps: ?php $cases = array(5, 15, 30, 60, 90, 120); if (in_array($count, $cases)) { include 'page.php'; } ? Regards, Greg -- phpDocumentor http://www.phpdoc.org Jason Williard wrote: I am building a script that I would like to have do a specific task based on whether specific counts have been reached. Basically, the script checks for connectivity in a specific port. If the connectivity fails, it increases the count by 1. It does this every minute. I would like the script to page me at specific marker points (i.e. 5, 15, 30, 60, 90, 120, etc). Is there anyway to make an if statement or something similar to run in any case where the COUNT value equals one of the numbers in the array? Example: $cases = array( 5, 15, 30, 60, 90, 120 ); if ( $count = {ITEM IN $cases} ){ EXECUTE PAGE } Thanks, Jason Williard -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: Array -- If
Thanks! That did the trick. Jason Williard -Original Message- From: Greg Beaver [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 05, 2003 6:55 PM To: Jason Williard Cc: [EMAIL PROTECTED] Subject: Re: Array -- If Hi Jason, perhaps: ?php $cases = array(5, 15, 30, 60, 90, 120); if (in_array($count, $cases)) { include 'page.php'; } ? Regards, Greg -- phpDocumentor http://www.phpdoc.org Jason Williard wrote: I am building a script that I would like to have do a specific task based on whether specific counts have been reached. Basically, the script checks for connectivity in a specific port. If the connectivity fails, it increases the count by 1. It does this every minute. I would like the script to page me at specific marker points (i.e. 5, 15, 30, 60, 90, 120, etc). Is there anyway to make an if statement or something similar to run in any case where the COUNT value equals one of the numbers in the array? Example: $cases = array( 5, 15, 30, 60, 90, 120 ); if ( $count = {ITEM IN $cases} ) { EXECUTE PAGE } Thanks, Jason Williard -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array to string?
When I needed it I could'n find it so I made my own. function arrayToStr( $arr ){ $str = ; while( true ){ $linea = current($arr); $str = $str . $linea; if( next($arr) == FALSE ){ break; } $str = str . \n;// a newline separates each element. } return $str; } Gabriel. Douglas Douglas [EMAIL PROTECTED] escribió en el mensaje news:[EMAIL PROTECTED] Hello everybody. Is there any built-in function to convert an array to string? Thanks. __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array, object problem....
point [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... Huhgood news :))) Just solved it : I'm on the role.. Y! :))) - Your solution would be helpful. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array encapsulate
On Fri, 12 Sep 2003 18:58:22 -0400, Bill [EMAIL PROTECTED] wrote: I'd like to do this, but it produces an error: if ($_POST{[detail][11][116]} !$_POST{[detailtext][19][114]}) { so I'm left doing this if ($_POST[detail][11][116] !$_POST[detailtext][19][114]) { How can I encapsulate the array so it is a multi-dimensional array and not just a string length? It is rather unclear what you mean, the first syntax is wrong and thus is why it produces an error. The second one is the proper way to access a multi-dimensional array. Curt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: ARRAY QUESTION
Dale Hersh [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have a question regarding the count function. Here goes: Lets pretend I have this array called myStuff. If I add two elements to myStuff and call the count function, I will get a result of 2. My question is how do I re-initialize the array after adding elements so when I call the count function on the array, I get a result of 0. Thanks, Dale I assume you want to KEEP the other values in the array? If not then you can just unset($myStuff). If you do want to keep the array intact then I suppose you could store the count in a variable $counta, add more elements to the array (or not), take the count again and store it in a new variable $countb, then subtract the values $count = abs($counta - $countb); abs() converts to the absolute value if the result is negative. - Kevin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Dump
look at strlen() at php.net Daniel J. Rychlik [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hmm, I just noticed that array dump counts the number of charaters and white space and lables that number string... What function name is that ? The string counter I mean ? -Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Sorting
I found this Great PHP Starter site check it out http://www.htmlite.com/PHPintro.php Ashley M. Kirchner [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have an array that looks like this: $i = 0; $item[$i] = array( 'link' = 'http://...', 'image' = '/images/image.jpg', 'title' = 'some title', 'price' = '$14.00', 'cat'= 'Frames', 'author' = 'Pinochio', 'artist' = '', 'asin' = '010101', 'manufacturer' = 'Post' ); $i++; $item[$i] = array( 'link' = 'http://...', 'image' = '/images/something.jpg', 'title' = 'this is fun', 'price' = '$2.99', 'cat'= 'Card', 'author' = 'Mickey', 'artist' = '', 'asin' = '1116221', 'manufacturer' = 'Kraft' ); $i++; etc., etc. I would like to sort $items based on the manufacturer of each array within. So that, in the above example, the second one would come before the first. Is there a way to do that? -- H| I haven't lost my mind; it's backed up on tape somewhere. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / WebSmith . 800.441.3873 x130 Photo Craft Laboratories, Inc.. 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array
Your code works fine here (Apache 1.3.27/PHP 4.3.2) However you can try $room_type=array(); $room_type[0]=Array(); $room_type[0][0]=4; echo BRvalue in array is .$room_type[0][0]; HTH R'twick Diana Castillo [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] If I write a code like this, $room_type=array(); $room_type[0][0]=4; echo BRvalue in array is .$room_type[0][0]; yet I dont get any results out, what did i do wrong? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array[array]
Try this: Array[i][j] where i is the index of the array stored in the array and j is the index of the value in the stored array. Erich Kolb [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] How do I get a value from an array thats inside of an array?
[PHP] Re: Array sorting
never done it, but check out: http://www.php.net/manual/en/function.array-multisort.php On Sat, 8 Feb 2003, Zydox wrote: My question is if anyone have any idé on how to sort this array so that the names and ages are sorted after Close Friend, Friend, Wife and last Family... $A[] = array (Nils, 23, Friend); $A[] = array (Emma, 21, Friend); $A[] = array (Cassie, 21, Wife); $A[] = array (Zydox, 23, Friend); $A[] = array (Patrick, 24, Close Friend); $A[] = array (Kalle, 40, Family); $A[] = array (John, 10, Close Friend); $A[] = array (Anna, 12, Friend); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array find a element
look at array_key_exists Narciso Miguel Rodrigues [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Is possible to do something like if ($username in $users) ... or i need to do a foreach($user){...} Thks [MsR] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array with session
You should have session_start(); on every page that you want to hold the session. The way I would do what you are trying to achieve is go the $_SUPERGLOBALS way.. on the submit_information.php page: ?php session_start(); $_SESSION['image'] = $_POST['image']; foreach($_SESSION['image'] as $foo){ echo $foo . br\n; } ? Also, another good way of debugging etc is to use the print_r() function (http://www.php.net/print_r) If you do : pre?php print_r($_SESSION);?/pre This produces a nice formatted look at the the session arrays/structures - same goes for all arrays. Hope that helps, Craig Laurence [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... hello everyone, I'm trying to get some images value from a checkbox putting them in a session to preserve the data. The array works perfectly without the session_start() and session_register. can anyone help? html script html head title/title /head body form action=submit_information.php method=post input type=checkbox name=Image[] value=Image_One img src=.gif name=Image_Onebr input type=checkbox name=Image[] value=Image_Two img src=.gif name=Image_Twobr input type=checkbox name=Image[] value=Image_Three img src=.gif name=Image_Twobr input type=checkbox name=Image[] value=Image_four img src=.gif name=Image_Onebr input type=checkbox name=Image[] value=Image_five img src=.gif name=Image_Twobr input type=checkbox name=Image[] value=Image_six img src=.gif name=Image_Twobr input type=submit value=submit /form /body /html php script: submit_information.php ?php session_start(); session_register(Image); $count = count($Image); for ($i=0; $i$count; $i++) { echo $Image[$i]; } //I also tried that /*foreach ($Image as $i= $Img) { $Img == $Image[$i]; echo $Img; }*/ ? - With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array with session
Files are attached.. Craig Craig [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... You should have session_start(); on every page that you want to hold the session. The way I would do what you are trying to achieve is go the $_SUPERGLOBALS way.. on the submit_information.php page: ?php session_start(); $_SESSION['image'] = $_POST['image']; foreach($_SESSION['image'] as $foo){ echo $foo . br\n; } ? Also, another good way of debugging etc is to use the print_r() function (http://www.php.net/print_r) If you do : pre?php print_r($_SESSION);?/pre This produces a nice formatted look at the the session arrays/structures - same goes for all arrays. Hope that helps, Craig Laurence [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... hello everyone, I'm trying to get some images value from a checkbox putting them in a session to preserve the data. The array works perfectly without the session_start() and session_register. can anyone help? html script html head title/title /head body form action=submit_information.php method=post input type=checkbox name=Image[] value=Image_One img src=.gif name=Image_Onebr input type=checkbox name=Image[] value=Image_Two img src=.gif name=Image_Twobr input type=checkbox name=Image[] value=Image_Three img src=.gif name=Image_Twobr input type=checkbox name=Image[] value=Image_four img src=.gif name=Image_Onebr input type=checkbox name=Image[] value=Image_five img src=.gif name=Image_Twobr input type=checkbox name=Image[] value=Image_six img src=.gif name=Image_Twobr input type=submit value=submit /form /body /html php script: submit_information.php ?php session_start(); session_register(Image); $count = count($Image); for ($i=0; $i$count; $i++) { echo $Image[$i]; } //I also tried that /*foreach ($Image as $i= $Img) { $Img == $Image[$i]; echo $Img; }*/ ? - With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs begin 666 submit_information.php M/#]P:' -@T*7-EW-I;VY?W1AG0H*3L-@T*21?4T534TE/3ELG:6UA M9V4G72 ](1?4$]35%LG26UA9V4G73L-@T*69OF5A8V@H)%]315-324]. M6R=I;6%G92==(%S(1F;V\IPT*#0H)65C:\@)9O;R N((\8G(^7XB M.PT*#0H)?0T*#0H_/@T*/'!R93X-@D\/W!H!PFEN=%]R*1?4T534TE/ .3BD[(#\^#0H\+W!R93X` ` end begin 666 index.html M/AT;6P^#0H\:5A9#X-CQT:71L93X\+W1I=QE/@T*/]H96%D/@T*#0H\ M8F]D3X-@D\9F]R;2!A8W1I;VX](G-U8FUI=%]I;F9OFUA=EO;BYP:' B M(UE=AO9#TB]S=(^#0H)2!);6%G95]/;F4\:6YP=70@='EP93TB8VAE M8VMB;W@B(YA;64]26UA9V5;72!V86QU93TB26UA9V5?3VYE(CX\8G(^#0H) M2!);6%G95]4=V\\:6YP=70@='EP93TB8VAE8VMB;W@B(YA;64]26UA9V5; M72!V86QU93TB26UA9V5?5'=O(CX\8G(^#0H)2!);6%G95]4:')E93QI;G!U M=!T7!E/2)C:5C:V)O(@;F%M93U);6%G95M=('9A;'5E/2));6%G95]4 M:')E92(^/)R/@T*0D@26UA9V5?9F]UCQI;G!U=!T7!E/2)C:5C:V)O M(@;F%M93U);6%G95M=('9A;'5E/2));6%G95]F;W5R(CX\8G(^#0H)2!) M;6%G95]F:79E/EN'5T('1Y4](F-H96-K8F]X(B!N86UE/4EM86=E6UT@ M=F%L=64](DEM86=E7V9I=F4B/CQBCX-@D)($EM86=E7W-I#QI;G!U=!T M7!E/2)C:5C:V)O(@;F%M93U);6%G95M=('9A;'5E/2));6%G95]S:7@B M/CQBCX-@D)(#QI;G!U=!T7!E/2)S=6)M:70B('9A;'5E/2)S=6)M:70B ?/@T*3PO9F]R;3X-CPO8F]D3X-CPO:'1M;#X-@`` ` end -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Searching
i have an array like: Array ( [1] = Array ( [alias] = foo ... ) [2] = Array ( [alias] = bar ... ) ... ) I need some way to find out, if an alias foo is in the array. Any idea how to do this? Assuming your outer array is called $array_of_arrays: ?php $found = 0; foreach ($array_of_arrays as $array) { if ($array['alias'] == 'foo') { $found = 1; break; } } if ($found) { // you found it! } else { // too bad! } ? Or, you can look at this: http://www.php.net/manual/en/function.in-array.php if you're not sure what key 'foo' will be at, or this: http://www.php.net/manual/en/function.array-search.php if you're not sure what key 'foo' will be at and you want to know what that key is. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: =array within an html table=
I think this is more of an HTML problem than a PHP... Put it inside td$here/td (or trtd$here/td/tr whichever you need) and I'm sure the problem will go away. - E "Anthony Ritter" [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I'd like to have the record data - $current - *within* the html table but if I run this script it is on a line outside of the table: ? $content = file("http://waterdata.usgs.gov/ny/nwis/uv?format=rdbperiod=1site_no=01427 510"); array_pop($content); $current = array_pop($content); print("table border=1"); print("trtdUSGS/tdtdStation/tdtdDate/tdtdTime/tdtdHeight /tdtdCFS/tdtdTemperature/td"); print("/table"); print($current); ? ... ...and if I run this script, the record - $current - is outside above the table - not within it. ? $content = file("http://waterdata.usgs.gov/ny/nwis/uv?format=rdbperiod=1site_no=01427 510"); array_pop($content); $current = array_pop($content); print("table border=1"); print("trtdUSGS/tdtdStation/tdtdDate/tdtdTime/tdtdHeight /tdtdCFS/tdtdTemperature/td"); print($current); print("/table"); ? . Any help would be greatly appreciated. Tony Ritter -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Javascript
if you have an array in javascript: array1 = [1,2,3,4,5,6,7,8,'test']; etc... you can join it in JavaScript to make it a one string as: array1 = array1.join('|'); then split in PHP to make it back an array: ? $array1 = explode('|', $array1); ? good luck, Kale [EMAIL PROTECTED] wrote in message 002c01c254cc$fe8eace0$7800a8c0@leonard">news:002c01c254cc$fe8eace0$7800a8c0@leonard... Hy, I have an array make with a javascript. How can I read values with PHP from it? Kale. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array query - finding the key for a value
can do this: $array = array('apple', 'pear', 'orange', 'apricot'); $array = array_flip($array); $keyword = 'orange'; echo found '$orange' @ index: . $array[$keyword]; Don't use this method though! It makes your program slow! Elias Tim Fountain [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... This may be a silly question, but I'm used to being able to find PHP functions to do whatever I want, but I can't find one to do this! If I have an array like this: [0] - 'apple'; [1] - 'pear'; [2] - 'orange'; [3] - 'apricot'; I know I can use in_array() to check whether, say, 'orange' is in the array; but how do I then find out which index 'orange' is at? -- Tim Fountain ([EMAIL PROTECTED]) http://www.tfountain.co.uk/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array and a class
solved it thx anyway Pafo [EMAIL PROTECTED] skrev i meddelandet [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... i got my nice looking class like this: ?php class Relic { var $RelicName; var $RelicType; var $RelicRealm; var $RelicOwner; function PrintInfo() { print $this-RelicName : $this-RelicType : $this-RelicRealm : $this-RelicOwnerbr; } function CheckForPrint() { if ($this-RelicName == || $this-RelicType == || $this-RelicRealm == || $this-RelicOwner == ) { return false; } else { return true; } } function Clean() { $this-RelicName = ; $this-RelicType = ; $this-RelicRealm = ; $this-RelicOwner = ; } function SetName($name) { $this-RelicName = $name; } function SetType($type) { $this-RelicType = $type; } function SetRealm($realm) { $this-RelicRealm = $realm; } function SetOwner($owner) { $this-RelicOwner = $owner; } function DebugPrint() { print $this-RelicName; } } $temp = new Relic(); $temp-SetName(test); $temp-DebugPrint(); ? but the thing is i want an array that is based on my class, so i want to use $relicarray[1]-DebugPrint(); how does it work,, anyone that can give me a working example, cause i cant find any :/ regards patrick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: ARRAY, IF INSERT
César aracena wrote: The catch would be to make PHP to auto assign the relatives level by knowing it has to start from $i=1 and loop $i++ until no other kid is inserted. Now that I write it, it seems I could use a for loop, but what should be the structure of it using the $name 0 you told me? the name 0 was a sql-query - it will return a ressource which will enable you to make something like $i=0; while($row = mysql_fetch_assoc($nameless_result){ #psuedo-code# # mysql_query=(insert into table set relativenumber = 'jr$i' where ID=$row[ID]); } regards Jesper Brunholm btw: please do not write to my private email -- Phønix - Danish folk music from young musicians - http://www.phonixfolk.dk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: ARRAY, IF INSERT
the name 0 was a sql-query - it will return a ressource which will enable you to make something like $i=0; while($row = mysql_fetch_assoc($nameless_result){ #psuedo-code# # mysql_query=(insert into table set relativenumber = 'jr$i' where ID=$row[ID]); } [César L. Aracena] I think you just showed me the smartest way of doing it. After I deal with a deadline here, I will change my hard coded script in order to try it... will let you know. Thanks a lot. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: ARRAY, IF INSERT
(i am new to these groups, but shouldn't there be a follow-up-to on a X-post?) César aracena wrote: I have this form in which one Administrator can insert new members and after that, in another page, a form where he/she can insert the new members sons daughters. I want to display a table with text inserts into the admin can type lets say a maximum of 5 kids in the second page. The number doesn't matter if you design you db well (I suppose we are talking database). I suppose that you have a table with members with unique ID's? Make a new table with relatives, where you connect to their parents through a ParentID-field This way you'll avoid empty fields for the folks with eg. only 2 sons :-) The query for father + sons and daughters would then be like mysql_query( select members.Name, members.ID, relatives.Name as RelativeName, relatives.ID from parents, relatives where parents.ID = relatives.ParentID ) The members table will have one memberID field (which will be shared between parents and kids) and a levelID which will grant 0 for the parent and 1, 2, 3, 4, 5 for the kids. You _can_ put them all in the same table, but I suppose that you have a lot of data stored on the parents/members, that is non-existing and irellevant for the children - this will give a lot of empty fields, which is why i propose the solution above... Now, how do I tell PHP to make an array from the kids input, but only from the fields in which lets say the name field was filled out in order to spend the necessary tables rows. Another thing the Array should also specify new levelIDs for each kid from 1 to 5. It would be great if you also show me how to deal with it after its created. It's easy to select only rows with contents for at certain field: select * from relatives where Name 0 I hope this was of some help? regards Jesper Brunholm -- Phønix - Danish folkmusic from young musicians - http://www.phonixfolk.dk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: ARRAY, IF INSERT
Thanks for the input. I wasn't considering the possibility of making a new table for kids until now which seems pretty logic when trying to save space. The only thing missing now is how to assign a unique relation number for each kid/relative. That's 1 for the first born, 2 for the second one, etc... and it can't be done by auto_incrementing, for it will start over when a new member is inserted... i.e. the relatives table should show: Member level nameaddress 00251 Jr.1same as 0025/0 00252 Jr.2same as 0025/0 00261 Jr.1same as 0026/0 00262 Jr.2same as 0026/0 00263 Jr.3same as 0026/0 The catch would be to make PHP to auto assign the relatives level by knowing it has to start from $i=1 and loop $i++ until no other kid is inserted. Now that I write it, it seems I could use a for loop, but what should be the structure of it using the $name 0 you told me? Thanks -Original Message- From: Jesper Brunholm [mailto:[EMAIL PROTECTED]] Sent: Friday, June 21, 2002 6:56 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: [PHP] Re: ARRAY, IF INSERT (i am new to these groups, but shouldn't there be a follow-up-to on a X-post?) César aracena wrote: I have this form in which one Administrator can insert new members and after that, in another page, a form where he/she can insert the new members sons daughters. I want to display a table with text inserts into the admin can type lets say a maximum of 5 kids in the second page. The number doesn't matter if you design you db well (I suppose we are talking database). I suppose that you have a table with members with unique ID's? Make a new table with relatives, where you connect to their parents through a ParentID-field This way you'll avoid empty fields for the folks with eg. only 2 sons :-) The query for father + sons and daughters would then be like mysql_query( select members.Name, members.ID, relatives.Name as RelativeName, relatives.ID from parents, relatives where parents.ID = relatives.ParentID ) The members table will have one memberID field (which will be shared between parents and kids) and a levelID which will grant 0 for the parent and 1, 2, 3, 4, 5 for the kids. You _can_ put them all in the same table, but I suppose that you have a lot of data stored on the parents/members, that is non-existing and irellevant for the children - this will give a lot of empty fields, which is why i propose the solution above... Now, how do I tell PHP to make an array from the kids input, but only from the fields in which lets say the name field was filled out in order to spend the necessary tables rows. Another thing the Array should also specify new levelIDs for each kid from 1 to 5. It would be great if you also show me how to deal with it after its created. It's easy to select only rows with contents for at certain field: select * from relatives where Name 0 I hope this was of some help? regards Jesper Brunholm -- Phønix - Danish folkmusic from young musicians - http://www.phonixfolk.dk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array of objects???
Might just be a typo, but in the function prototype for AddUser(), you have $oUser, but the array_push() argument says $objUser. J J. Anderson Scarbrough wrote: I have two classes. Organization and users. In the organization class I am try to keep an array of user objects but it does not seem to be taking. Can any help? See code below. class Organization { var $users = array(); function AddUser($oUser) { array_push($this-users, $objUser); } function numberOfUsers() { return count($this-users); } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php