PHP - Understanding Oci_bind_by_name() And How Array Elements Can Be Trusted
I'm trying to use oci_bind_by_name() to bind elements of an array, but I'm confused by a few things. For a start: http://ca2.php.net/manual/en/function.oci-bind-by-name.php (see example #3) says that Code: [Select]
foreach ($ba as $key => $val) { oci_bind_by_name($stid, $key, $val); } won't work. Fair enough, because $val is always the same variable so nothing will be bound when the loop is done, so Code: [Select] foreach ($ba as $key => $val) { oci_bind_by_name($stid, $key, $ba[$key]); } is necessary. But what's wrong with Code: [Select] foreach ($ba as $key => &$val) { oci_bind_by_name($stid, $key, $val); }? I would expect it to work just as well w/a slight performance increase. Another thing I'd like to know is how effective the binding is when array elements are reassigned. If I have something like Code: [Select] $ba[':column_name'] = 'something'; oci_bind_by_name($stid, ':column_name', $ba[':column_name']); ... $ba[':column_name'] = 'something_else';will this give me what I expect? Is $ba[':column_name'] guaranteed to still point to the same memory? Similar TutorialsHi, I have a form that I want to allow users to be able to add specific links, some are set types (domains) and just require the iser to enter the link, however, one is for whatever they wish and they must enter a name to describe it. Now im going to enter it into a database with the following columns: USER_ID || LINK_URL || LINK_TYPE || LINK_NAME Link name is optional (only needed if the link type is their own custom one), the link types are ID's related to a table of link types (facebook, twitter etc). Now I'm assuming that to differentiate the form elements for insertion into the database I would need to have a hidden form element with the type ID inside? However I don't really know how to go on from here. A small version of the form would be <input type="text" name="facebook_link" /> <input type="hidden" name="facebook_id value="1" /> <input type="text" name="twitter_link" /> <input type="hidden" name="twitter_id value="2" /> <input type="text" name="own_site" /> <input type="text" name="own_site_description" /> <input type="hidden name="own_site_id" value="3" /> However, I'm assuming this is wrong because I'll need to enter everything into an array won't I? I just can't get my head round it to out put thi results into a foreach statement. Can anybody help me please? Hello, I have a website where only a couple of people can access it, so the number of IPs logged in is very limited. Everything submitted by the 'admins' logged in is sent to a specific folder dependent of their IP Address. Again they can't access the website through a proxy or anything because there's a limited range of IPs that is allowed. Can I trust $_SERVER['REMOTE_ADDR'] to give a valid IP so the log-system would be 100 % stable and efficient ? I am able to get all elements but the 'i*' parts. How do I do this. Code: [Select] $formarray = array( 'name' => array( 'i1'=> array('a'=>'a1', 'b'=>'b1', 'c'=>'c1', 'd'=>'d1', 'e'=>'e1', 'f'=>'f1', 'g'=>'g1'), 'i2'=> array('a'=>'a2', 'b'=>'b2', 'c'=>'c2', 'd'=>'d2', 'e'=>'e2', 'f'=>'f2', 'g'=>'g2'), 'i3'=> array('a'=>'a3', 'b'=>'b3', 'c'=>'c3', 'd'=>'d3', 'e'=>'e3', 'f'=>'f3', 'g'=>'g3'), 'i4'=> array('a'=>'a4', 'b'=>'b4', 'c'=>'c4', 'd'=>'d4', 'e'=>'e4', 'f'=>'f4', 'g'=>'g4'), ) ); foreach ($formarray as $newarray => $a) { ?><strong><?=$newarray;?></strong><br><? foreach ($a as $key => $k) { foreach ($k as $b) { ?>"<?=$b;?>", <? } ?><br><? } //end of second foreach ?><br><br><br><? } //end of first foreach ?> I have a file that contains, among others, some links to other files. Those files contain links to other files and so on. What I want to do is to check if a file has already been opened, and if this is true I want the file not to be opened again. For this I created an array, but when the code returns to the first file the array is reseted. Can someone please help me? This is the code I created (I`m a beginer in php). Thanks function readImportFiles($taxonomyFile, $target_path, $fileName='', $ArrayOfTaxonomies = array()) { while(!feof($taxonomyFile)) { $line = fgets($taxonomyFile); //code for getting the $schemaLocation if ($schemaLocation && !in_array($schemaLocation, $ArrayOfTaxonomies)) { $ArrayOfTaxonomies[]= $schemaLocation; $importSchema = fopen($schemaLocation, "r"); $target_path = substr($schemaLocation, 0, (strlen($schemaLocation) - strlen(strrchr($schemaLocation, "/")))); readImportFiles($importSchema, $target_path, $schemaLocation, $ArrayOfTaxonomies); } } } Folks, How can i extract all the elements from the below Array? Arrayname is: $yahooterms Quote Array ( [ResultSet] => Array ( [Result] => Array ( => calla lily [1] => hair pins [2] => crystal crown [3] => red lingerie [4] => red crystal [5] => red wedding [6] => silver link [7] => necessary objects [8] => hair clip [9] => crystal necklace [10] => bridal wedding [11] => link bracelet [12] => appliques [13] => corsage [14] => organza [15] => swarovski crystal [16] => butterflies [17] => gems [18] => balloons [19] => sewing ) ) ) i am using Quote foreach($yahooterms as $replace) { echo $replace->ResultSet->Result; } But its not working.... I have gotten a lot of help with my php to get, read and parse and xml file for NFL scores... it was working really great but then I found something and now I have a new problem...
Currently it reads as follows:
$url="http://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml "; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); // get the url contents $data = curl_exec($ch); // execute curl request curl_close($ch); $xml = simplexml_load_string($data); $games = array( 'REG' => array(), 'WC' => array(), 'DIV' => array(), 'CON' => array(), 'SB' => array() ); foreach($xml->gms->g as $game) { // it's a single game // if (!empty($game['vtn'])) { $games[(string) $game['gt']][] = $game; } } ?> <div class='ticker'> <ul> <?php foreach ($games as $gametype => $subgames) { foreach ($subgames as $game) { if ($game['gt'] == 'REG') { ?> <li data-subcategory='Regular Season' data-category='Week <?= $game['w'] ?>' data-color='1979ab'> <a href='#'><b><?= $game['h'] ?> <?= $game['hs'] ?> <?= $game['v'] ?> <?= $game['vs'] ?></b></a> </li> <?php } else if ($game['gt'] == 'WC') { ?> <li data-subcategory='Round 1' data-category='Wild Card Games' data-color='1979ab'> <a href='#'><b><?= $game['htn'] ?> <?= $game['hs'] ?> <?= $game['vtn'] ?> <?= $game['vs'] ?></b></a> </li> <?php } else if ($game['gt'] == 'DIV') { ?> <li data-subcategory='Round 2' data-category='Divisional Games' data-color='14ab05'> <a href='#'><b><?= $game['htn'] ?> <?= $game['hs'] ?> <?= $game['vtn'] ?> <?= $game['vs'] ?> <?= $game['d'] ?> at <?= $game['t'] ?></b></a> </li> <?php } else if ($game['gt'] == 'CON') { ?> <li data-subcategory='Championship Games' data-category='Conference Games' data-color='000000'> <a href='#'><b><?= $game['htn'] ?> <?= $game['hs'] ?> <?= $game['vtn'] ?> <?= $game['vs'] ?> <?= $game['d'] ?> at <?= $game['t'] ?></b></a> </li> <?php } else if ($game['gt'] == 'SB') { ?> <li data-subcategory='<img src=localhost/joomla/modules/mod_scores/images/nfl.png>' data-category='Super Bowl' data-color='000000'> <a href='#'><b><?= $game['htn'] ?> <?= $game['hs'] ?> <?= $game['vtn'] ?> <?= $game['vs'] ?> <?= $game['d'] ?> at <?= $game['t'] ?></b></a> </li> <?php } } } ?> </ul> </div>I did notice that this will work fantastic during the post season but in regular season it's a new issue... the post season xml reads out team names likes this "Carolina Panthers" as one of the elements.. however during the regular season that gets shortened to: "CAR". How do I get it to read the xml and change "CAR" Into "Caroline Panthers"? I have to do this for all 32 teams... Thanks everyone! what am I doing wrong? I have an assoc array, but I can't seem to access it. Code: [Select] $var = Array ( 'domain' => asdfasdf.com 'port' => 2082 'adminuser' => admin 'INST_password' => adsfasdf 'adminnickname' => admin 'adminemail' => admin@asdfasdf.com 'sitename' => Play Bingo Online Austrailia 'description' => How to play bingo online in Australia 'site_root_path' => /home/chris/public_html/ 'theme' => default 'anchor_one' => How to play bingo online in Australia 'anchor_two' => play bingo 'anchor_three' => bingo online ) if( empty($var['domain']) ) exit; the code exits everytime. What am I missing? Hi Guys, I have an array that contains a few records from mysql. The array looks like so Array ( [0] => Array ( [id] => 1 [name] => New Product [url] => New-Product [title] => Title Used On Heading [description] => Write a 3 to 5 Paragraph summary of product [preview_image] => 0 [body_image] => 0 [status] => 1 ) [1] => Array ( [id] => 2 [name] => New Product [url] => New-Product [title] => Title Used On Heading [description] => Write a 3 to 5 Paragraph summary of product [preview_image] => 0 [body_image] => 0 [status] => 0 ) ) I am trying to modify the preview_image value on each of the arrays in this array like so; //modify the products array foreach($data['raw_products'] as $data['products']) { //set the preview image row $data['products']['preview_image'] = anchor('admin/list_products/#', "View IMG", array("onHover" => "admin.previewIMG('".$data['products']['preview_image']."')", "class" => "noLink")); //set the body image row $data['products']['body_image'] = anchor('admin/list_products/#', "View IMG", array("onHover" => "admin.bodyIMG('".$data['products']['body_image']."')", "class" => "noLink")); } It works fine for one record, but then when I print_r($data['products']) I only see one record. Any help would be greatly appreciated. Hi, I'm a PHP novice and trying to print out elements of what appears to be a multi-dimensional array, but I can't figure it out. I'm able to use print_r() to dump the array. Array ( [0] => 18485 [1] => Array ( [1] => Array ( [isPublished] => 1 [dateAdded] => 2019-07-18T16:13:28+00:00 [dateModified] => 2020-01-29T18:37:45+00:00 [createdBy] => [createdByUser] => Support [modifiedBy] => [modifiedByUser] => [id] => 1 [points] => 0 [color] => [fields] => Array ( [core] => Array ( [points] => Array ( [id] => 9 [label] => Points [alias] => points [type] => number [group] => core [object] => lead [is_fixed] => 1 [default_value] => 0 [properties] => a:0:{} [value] => 0 [normalizedValue] => 0 ) [last_active] => Array ( [id] => 19 [label] => Date Last Active [alias] => last_active [type] => datetime [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => 2020-01-29 18:37:47 [normalizedValue] => 2020-01-29 18:37:47 ) [title] => Array ( [id] => 1 [label] => Title [alias] => title [type] => lookup [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:1:{s:4:"list";a:3:{i:0;s:2:"Mr";i:1;s:3:"Mrs";i:2;s:4:"Miss";}} [value] => [normalizedValue] => ) [firstname] => Array ( [id] => 2 [label] => First Name [alias] => firstname [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => Andy [normalizedValue] => Andy ) [lastname] => Array ( [id] => 3 [label] => Last Name [alias] => lastname [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => Towne [normalizedValue] => Towne ) [company] => Array ( [id] => 4 [label] => Primary company [alias] => company [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [position] => Array ( [id] => 5 [label] => Position [alias] => position [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [email] => Array ( [id] => 6 [label] => Email [alias] => email [type] => email [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => andy.towne@example.com [normalizedValue] => andy.towne@example.com ) [phone] => Array ( [id] => 8 [label] => Phone [alias] => phone [type] => tel [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [mobile] => Array ( [id] => 7 [label] => Mobile [alias] => mobile [type] => tel [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [address1] => Array ( [id] => 11 [label] => Address Line 1 [alias] => address1 [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [address2] => Array ( [id] => 12 [label] => Address Line 2 [alias] => address2 [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [city] => Array ( [id] => 13 [label] => City [alias] => city [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => Boston [normalizedValue] => Boston ) [state] => Array ( [id] => 14 [label] => State [alias] => state [type] => region [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => Massachusetts [normalizedValue] => Massachusetts ) [zipcode] => Array ( [id] => 15 [label] => Zip Code [alias] => zipcode [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [timezone] => Array ( [id] => 18 [label] => lead.field.timezone [alias] => timezone [type] => timezone [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => America/New_York [normalizedValue] => America/New_York ) [country] => Array ( [id] => 16 [label] => Country [alias] => country [type] => country [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => United States [normalizedValue] => United States ) [fax] => Array ( [id] => 10 [label] => Fax [alias] => fax [type] => tel [group] => core [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [preferred_locale] => Array ( [id] => 17 [label] => Preferred Locale [alias] => preferred_locale [type] => locale [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [attribution_date] => Array ( [id] => 20 [label] => Attribution Date [alias] => attribution_date [type] => datetime [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [attribution] => Array ( [id] => 21 [label] => Attribution [alias] => attribution [type] => number [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:2:{s:9:"roundmode";i:4;s:9:"precision";i:2;} [value] => [normalizedValue] => ) [website] => Array ( [id] => 22 [label] => Website [alias] => website [type] => url [group] => core [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [number_of_email_users] => Array ( [id] => 45 [label] => Number of Email Users [alias] => number_of_email_users [type] => number [group] => core [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:2:{s:9:"roundmode";s:1:"3";s:9:"precision";s:0:"";} [value] => [normalizedValue] => ) ) [social] => Array ( [facebook] => Array ( [id] => 23 [label] => Facebook [alias] => facebook [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [foursquare] => Array ( [id] => 24 [label] => Foursquare [alias] => foursquare [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [instagram] => Array ( [id] => 26 [label] => Instagram [alias] => instagram [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [linkedin] => Array ( [id] => 27 [label] => LinkedIn [alias] => linkedin [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [skype] => Array ( [id] => 28 [label] => Skype [alias] => skype [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [twitter] => Array ( [id] => 29 [label] => Twitter [alias] => twitter [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) ) [personal] => Array ( ) [professional] => Array ( ) [all] => Array ( [id] => 1 [points] => 0 [last_active] => 2020-01-29 18:37:47 [title] => [firstname] => Andy [lastname] => Towne [company] => [position] => [email] => andy.towne@example.com [phone] => [mobile] => [address1] => [address2] => [city] => Boston [state] => Massachusetts [zipcode] => [timezone] => America/New_York [country] => United States [fax] => [preferred_locale] => [attribution_date] => [attribution] => [website] => [number_of_email_users] => [facebook] => [foursquare] => [instagram] => [linkedin] => [skype] => [twitter] => ) ) [lastActive] => 2020-01-29T18:37:47+00:00 [owner] => [ipAddresses] => Array ( [0] => Array ( [ipAddress] => 104.247.39.34 [id] => 5043 [ipDetails] => Array ( [city] => Boston [region] => Massachusetts [zipcode] => [country] => United States [latitude] => 42.36 [longitude] => -71.0545 [isp] => [organization] => [timezone] => America/New_York [extra] => ) ) [1] => Array ( [ipAddress] => 74.125.210.26 [id] => 6162 [ipDetails] => Array ( [city] => Hayward [region] => California [zipcode] => [country] => United States [latitude] => 37.6736 [longitude] => -122.0944 [isp] => [organization] => [timezone] => America/Los_Angeles [extra] => ) ) [2] => Array ( [ipAddress] => 73.126.166.11 [id] => 3069 [ipDetails] => Array ( [city] => Everett [region] => Massachusetts [zipcode] => [country] => United States [latitude] => 42.415 [longitude] => -71.0527 [isp] => [organization] => [timezone] => America/New_York [extra] => ) ) ) [tags] => Array ( ) [utmtags] => Array ( ) [stage] => [dateIdentified] => 2019-07-18T16:13:28+00:00 [preferredProfileImage] => gravatar [doNotContact] => Array ( ) [frequencyRules] => Array ( ) ) ) ) This output was produced using print_r($array);
I'm trying to access our contacts using the vendor's PHP API, but I'm not much of a PHP programmer. The array is stored in $contacts, using the vendor's getList() function. I believe I'm able to download the whole list of contacts in an array, but I can't iterate through it. I'd like to print out the elements of the array in CSV format.
$contacts = $contactApi->getList($searchFilter, $start, $limit, $orderBy, $orderByDir, $publishedOnly, $minimal); I've also tried something like this:
foreach ($contacts as $contact) {
I used DOM to parse data from html, then I made the data go into an array. the array now looks like Array([0]->street[1]->city, st, zip[2]->phone[3]->fax) and it is quite a long array. The problem is that when there is no fax number on the html, it doesnt show the fax on the array, so when I am trying to loop through this in a table it is throwing off my cells. Is there a way to delete all entries in an array that include Fax:* ? Is there a way to exclude all nodes that have Fax* using DOM? My current DOM looks like... Code: [Select] $address = $xpath->query('//td[@id="addressText"]'); I have converted xml into an array with no problems, however I'm having difficulty outputting the various attributes. Here is a sample: Code: [Select] [0] => Array ( [@attributes] => Array ( [YourId] => 1082-1 [Name] => Woodwards Metals [Description] => ) ) The bit that is confusing me is the @attributes part. How would I output the 'Name' element for example? So I'm trying to unset array elements that don't contain "thumbnail" in the filename. Seems simple, but it's not working.
function generateImage3 ($category, $imageornot, $Imagepointer) { if($imageornot == 1){ $var = get_cwd_uploads().'\\'.$Imagepointer; // get_cwd_uploads() is a custom function $scanned_directory = array_diff(scandir($var), array('..', '.')); foreach($scanned_directory as $elements){ $pos = strpos($elements, 'thumbnail'); if($pos === FALSE){ unset($scanned_directory[key($elements)]); } } // irrelevant code Any help appreciated. Hey everyone. I have a project I'm working on and am having some issues. I'm trying to build a web-based FTP program for a client. I have all the ftp stuff down packed, but I'm having issues with connecting to a local computer. I can get the directories an a local disk viewing and changing just fine, my problem is I'm wondering how I might pass each value of the array generated by the scandir() function into a form element value such as a checkbox. The furthest I've been able to get with this is displaying the last object in the array. Here is some code: <?php foreach ($d as $key => $val) { echo "<table width=auto height=auto border=0> <tr> <td><img src=".$icon." width=16 height=16></td> <td>".$val."</td> <td><input name=selection type=checkbox value=".$val."></td> </tr> </table>"; ?> All I get is the last item in the array. any help is appreciated. Suppose I have 2 arrays like the two below. I want to change each element of the first array. I want to add [‘person_id’] => 3 to each element and I want to add the [name] element from each element of the second array to each element of the first, with the [name] value corresponding. i.e. [name] from the first element in array 2 added to the first element of array one, [name] from the second element of array two added to the second element of array one, and[name] from the third element of array two added to the third element of array one. The element can be called "name" in each element of the first array. Thus the person_id would be the same in all elements of array one and the name element from array two would be added, changing for each element. It’s kind of a foreach in a foreach and I couldn’t figure out how to do it. array_walk might be useful as well though I couldn’t figure that our either. What’s happening here is that I am uploading three image files and want to insert the information about each file into corresponding file fields in a row determined by the person_id, extracting the image filenames from array 2. Thanks for help with this, —Kenoli Array 1 ( [person_id] => 3 [1] => Array ( ['title'] => qwerqwer ['medium'] => dfsadfasda ) [2] => Array ( ['title'] => sadfasdfad ['medium'] => Asdfsadf ) [3] => Array ( ['title'] => asdfsadf ['medium'] => Sadfsedf ) [submit] => Submit ) Array 2 ( [image1] => Array ( [name] => _DSC0080.jpg [type] => image/jpeg [tmp_name] => /Applications/XAMPP/xamppfiles/temp/phpxY22EN [error] => 0 [size] => 1784656 ) [image2] => Array ( [name] => _DSC0030.jpg [type] => image/jpeg [tmp_name] => /Applications/XAMPP/xamppfiles/temp/phpy2Wq43 [error] => 0 [size] => 1724811 ) [image3] => Array ( [name] => _DSC0001.jpg [type] => image/jpeg [tmp_name] => /Applications/XAMPP/xamppfiles/temp/phpZSBkAp [error] => 0 [size] => 2278345 ) )
I have it to where it groups two parts of the Array randomly but I need to make it where it won't pair the same together, or if it has already been paired with a team then use another team. Each value of the array can only be used once. Here is my code shuffle($teamname); $loopCount = $games; for ($i = 0; $i < $loopCount; $i++) { $player1 = array_pop($teamname); $player2 = array_pop($teamname); if(is_null($player1)) { echo 'Not enough different teams to create '.$games.' games'; break; } // output to screen echo "Team: " . $player1 . " Vs Team: " . $player2 . "<br />"; } } I have created a session array on one page and stored some values as $_SESSION['users'] = array( "id" => $row['id'], "fname" => $row['ufname'], "lname" => $row['ulname'] ); and then on another page I have some more values for the same session array "boss" => $row['bossid'], "tasks" => $row['tasks'], "timeframe" => $row['tframe'] I want to add these values into session array both keys and values. is there any way of doing this? Please help Hello, I have two arrays: $questions, which has 'question_id' as one of its keys and $assignment_questions which is a subset of $questions, pulled off my database. Using php, I'd like to construct a 3rd array which takes my $questions array and removes from it any question that has a question_id which can be found in both $questions and $assignment_questions, in addition to the other values associated with a particular question_id. For example, $questions has: question_id, solution, author (and other keys). Is there any way to check if a particular key matches and then zap out all of the corresponding fields (solution, author, etc.)? Thanks! Code: [Select] <? $i=1; $analysts[$i] = array(0=>'alpha'); $regions[$i] = array(0=>'beta'); $countries[$i] = array(0=>'gamma'); $provinces[$i] = array(0=>'delta'); $events[$i] = array(0=>'epsilon'); $selectable_document_elements = array ( 0=> analysts, 1=> regions, 2=> countries, 3=> provinces, 4=> events ); foreach($selectable_document_elements as $value) { echo $value; print_r($$value[$i]); echo "</br>"; } ?> I can't seem to call $$value[$i], however when I leave off the [$i] part Code: [Select] print_r($$value); I get the individual elements... Code: [Select] analystsArray ( [1] => Array ( [0] => alpha ) ) regionsArray ( [1] => Array ( [0] => beta ) ) countriesArray ( [1] => Array ( [0] => gamma ) ) provincesArray ( [1] => Array ( [0] => delta ) ) eventsArray ( [1] => Array ( [0] => epsilon) ) However, I would like to get the 1 part of the array, in this example. Is there a magic trick to calling variable arrays' individual elements? Can anyone let me know what I am doing wrong. I am sure it will (after the fact) be obvious, but I don't see it right now. Wish to remove all array elements which do not implement ValidatorCallbackInterface. Thanks <?php interface ValidatorCallbackInterface{} class ValidatorCallback implements ValidatorCallbackInterface{} function array_filter_recursive($input) { foreach ($input as &$value) { if (is_array($value)) { $value = array_filter_recursive($value); } } return array_filter($input, function($v) { return $v instanceOf ValidatorCallbackInterface; }); } function recursive_unset(&$array) { foreach ($array as $key => $value) { if (is_array($value)) { recursive_unset($value); if(empty($value)) { unset($array[$key]); } } elseif(!$value instanceOf ValidatorCallbackInterface) { unset($array[$key]); } } } $validatorCallback = new ValidatorCallback(); $rules=[ 'callbackId'=>"integer", 'info'=>[ 'arrayofobjects'=>[$validatorCallback], 'foo1'=>'bar1' ], 'foo2'=>'bar2', 'bla'=>[ 'a'=>'aa', 'b'=>'bb', ], 'singleobject'=>$validatorCallback ]; echo('original rules'.PHP_EOL); var_dump($rules); $desiredrules=[ 'info'=>[ 'arrayofobjects'=>[$validatorCallback] ], 'singleobject'=>$validatorCallback ]; echo('desired rules'.PHP_EOL); var_dump($desiredrules); echo('array_filter_recursive'.PHP_EOL); var_dump(array_filter_recursive($rules)); echo('recursive_unset'.PHP_EOL); recursive_unset($rules); var_dump($rules);
original rules array(5) { ["callbackId"]=> string(7) "integer" ["info"]=> array(2) { ["arrayofobjects"]=> array(1) { [0]=> object(ValidatorCallback)#1 (0) { } } ["foo1"]=> string(4) "bar1" } ["foo2"]=> string(4) "bar2" ["bla"]=> array(2) { ["a"]=> string(2) "aa" ["b"]=> string(2) "bb" } ["singleobject"]=> object(ValidatorCallback)#1 (0) { } } desired rules array(2) { ["info"]=> array(1) { ["arrayofobjects"]=> array(1) { [0]=> object(ValidatorCallback)#1 (0) { } } } ["singleobject"]=> object(ValidatorCallback)#1 (0) { } } array_filter_recursive array(1) { ["singleobject"]=> object(ValidatorCallback)#1 (0) { } } recursive_unset array(2) { ["info"]=> array(2) { ["arrayofobjects"]=> array(1) { [0]=> object(ValidatorCallback)#1 (0) { } } ["foo1"]=> string(4) "bar1" } ["singleobject"]=> object(ValidatorCallback)#1 (0) { } }
Hi guys I'm kinda stuck..so hopefully you guys can lend me a hand I've got an array containing date elements ("Y-m-d")... I'm trying to output some data into googlecharts..so i need to count how many elements that are in the array with todays date -1 day, todays date-2 days...todays date -3days etc... Up until a set number of days (for example 7 days, 14 days etc).. Any advice on how to go about to achieve this? |