PHP - Outputting Array Elements
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? Similar TutorialsI am trying to load all rows from a table in a database into a table on a webpage. I cannot understand why the following code does not work: Code: [Select] <?php ... echo "You are currently in a fleet. The details of the fleet are below.<br>"; $fleetName = $_SESSION['charFleetName']; $sqlFleetDetails = "SELECT * FROM `$fleetName`"; $queryFleetDetails = mysql_query($sqlFleetDetails); echo "<table>"; echo "<tr>"; echo "<th>Pilot</th>"; echo "<th>Ship</th>"; echo "<th>Type</th>"; echo "</tr>"; while($rowFleetDetails = mysql_fetch_array($queryFleetDetails)) { $charId = $rowFleetDetails['charId']; $charName = $rowFleetDetails['charName']; $shipHull = $rowFleetDetails['shipHull']; $shipType = $rowFleetDetails['shipType']; echo "<tr>"; echo "<td><a href=\"#\" onClick=\"CCPEVE.showInfo{1377, " . $charId . "}>" . $charName . "</a></td>"; echo "<td>" . $shipHull . "</td>"; if($shipType == 1) echo "<td>Logistics</td>"; if($shipType == 2) echo "<td>DPS Boat</td>"; if($shipType == 3) echo "<td>Sniper 120Km+</td>"; if($shipType == 4) echo "<td>Off-grid Booster</td>"; echo "</tr>"; } echo "</table><br>"; I originally had the $rowFleetDetails['charId'] and others in the echo instead of loading them into variables then echoing the variables but changed it to see if that was working, neither is. If I add an extra line outside of the while loop to echo the output of the array then the information is displayed fine, so I know that the information is being transferred from the table into the array correctly, but why is it not outputting properly in the While loop? Hello, this is my first post here.
I am trying to output the rows of a certain query in sequence after a POST has been requested.
I have been successful in getting the output in a pure php file but when I try to implement this in a web page with html/css, I can't echo the array in arbitrary locations after the post has processed.
This is the code which outputs successfully in a pure php file, but I need it to work in a <textarea> field as the results of a search
$rows2 = array(); $rows3 = array(); while($stmt->fetch()){ $rows2[] = $stratoparse; $rows3[] = $date; } $search = array(); for($i=0;$i<=$num_rows;$i++){ echo $rows3[$i].' '.$rows2[$i].'<br>'.'<br>'; } }To further iterate what I am asking. When errors are stored, you write something like $errors['username']="A username is required.";Then in any location of a webpage I can call this or show it, provided by this <?php isset($errors['username']) ? $errors['username']:" ");?>That is the same thing I am trying to do with this array which can be an arbitrary count of rows... I have not been successful in getting this to work... I have been told of string concatenation... I don't know what to do Thank you for any help I have a Q&A Form/script where registered Users can share there thoughts on 10 Questions. On the backend I have these tables: member, answer, question Thanks to some help last night, I have been able to do a LEFT join and store the above data in a multi-dimensional array which always stoes the 10 Questions, and also any Answers that the User may have responded to. (Questions are optional.) I am having a hell of a time DISPLAYING this multi-dimensional array. The key is that I want my PHP and array to stay at the top of my script and use minimal PHP in my HTML section. Here is how I query the data and build my array... // ******************** // Build Q&A Query. * // ******************** // Build query. $q7 = "SELECT q.id, q.question_no, q.question_text, a.answer_text FROM bio_question AS q LEFT JOIN bio_answer AS a ON q.id=a.question_id AND a.member_id =? ORDER BY q.question_no"; // Prepare statement. $stmt7 = mysqli_prepare($dbc, $q7); // Bind variables to query. mysqli_stmt_bind_param($stmt7, 'i', $memberID); // Execute query. mysqli_stmt_execute($stmt7); // Store results. mysqli_stmt_store_result($stmt7); // Check # of Records Returned. if (mysqli_stmt_num_rows($stmt7) > 0){ // Questions Found. // Bind result-set to variable. mysqli_stmt_bind_result($stmt7, $questionID, $questionNo, $questionText, $answerText); // Populate PHP array with Questions & Answers. $x=1; while (mysqli_stmt_fetch($stmt7)){ $thoughtsArray[$x] = array('questionID' => $questionID, 'questionText' => $questionText, 'answerText' => $answerText); $x=$x+1; } echo '<pre>'; print_r($thoughtsArray); echo '</pre>'; // Close prepared statement. mysqli_stmt_close($stmt7); And in my HTML Form, here is how I am attempting to dynamically build the Q&A section... <form id="changeAnswers" action="" method="post"> <fieldset> <legend>Change Profile Answers</legend> <?php echo '<p>TEST: ' . $thoughtsArray[4]['answerText'] . '</p>'; foreach($thoughtsArray as $questionNo => $qaArray) { echo '<label for="question' . $questionNo . '">' . $questionNo . '.) ' . $qaArray['questionText'] . '</label>'; echo '<textarea id="question' . $questionNo . '" name="thoughtsArray[' . $questionNo . '][\'answerText\']" cols="60" rows="2">' . (isset($questionNo]) ? "htmlentities($thoughtsArray[$questionNo]['answerText'], ENT_QUOTES" : '') . '</textarea>'; } ?> I am able to retrieve and display the Questions from my multi-dimensional array as seen above, however, for the life of me, I cannot get the Input Fields (with any Answers) to work properly. I either get compile errors, or the code runs but my Input Fields are blank even when an Answer should be displayed?! I am hoping this is just a syntax and/or reference error. I'm still new to arrays, so properly retrieving an Answer from a multi-dimensional array is really tricky for me!! So close and yet so far away?! Can someone please help me out?? Thanks, Debbie I have whiled my way through any number of forums and help pages so far. However, since I am not quite comfortable yet with PHP, I am not sure which option I have been given would be the right one. What I am trying to do: Create the source for a set of drop-down menus. The dropdown menu has columns, and then a H2 and P that go in each column, in varied numbers, so you have column1, h2 p; h2 p; h2 p column2, h2 p; h2 p etc....make sense? I am using an MySQL table as source so I can have a little CMS dashboard where I can change these and other values on the fly. So I have a MySQL table where I have a field that identifies the column (page name), and then values to fill the h2 and p tags. I.E.: page_name, content_title, content_text The idea, therefore, is to use PHP to figure out what the column names (that are repeated) in the mysql table and then create the dropdown based on the value in the subsidiary fields. Output is as a string in a variable value that is output via return (); My best estimation of how to do this is to use php to create a multidimensional array from the query result, where the first column is the page_name, followed by an array, the array being the remainder of the information. Based on information scrounged from other sources, I have come up with this so far: $query = "SELECT * FROM tbl_mainmenu WHERE mainmenu_type = '$mmtype'"; // what the query is $result = mysql_query ($query, $dbc); // connect to database and run query, setting the the result to dummy array variable '$result' // establish the multidimensional array $mmcontent_array = array (); //create the array where the values are content page and associated values in an array per each content page while ($result = mysql_fetch_assoc ()) { $page_name = $result['content_page']; $mmcontent_array['content_page'] = $result; } foreach ($mmContent_array[] as $key=>$value) { foreach () { $tmpelements[] = '<div class="col_2"><h2>' . $element[content_title] . "</h2>\n<p>" . $element[content_text] . "</p>\n</div>"; $elements = implode("\n",$tmpelements) . "\n" } $tmp[] = '<li><a href="#" class="drop">Products</a><!-- Begin Products Item -->\n<div class="dropdown_2columns"><!-- Begin 2 columns container -->' . $elements . 'whatever tags will close this') } Am I even in the ballpark? I am not sure which way to nest the foreach ()'s. The example I was working from used echo ()'s, and I am not sure if using $variable = implode () makes the task different. As a start, I am just wondering if I am creating the multidimensional array correctly? Hi all, I'm a first time poster here and I would really appreciate some guidance with my latest php challenge! I've spent the entire day googling and reading and to be honest I think I'm really over my head and need the assistance of someone experienced to advise the best way to go! I have a multi dimensional array that looks like (see below); the array is created by CodeIgniter's database library (the rows returned from a select query) but I think this is a generic PHP question as opposed to having anything to do with CI because it related to working with arrays. I'm wondering how I might go about searching the array below for the key problem_id and a value equal to a variable which I would provide. Then, when it finds an array with a the matching key and variable, it outputs the other values in that part of the array too. For example, using the sample data below. How would you recommend that I search the array for all the arrays that have the key problem_id and the value 3 and then have it output the value of the key problem_update_date and the value of the key problem_update_text. Then keep searching to find the next occurrence? Thanks in advance, as above, I've been searching really hard for the answer and believe i'm over my head! Output of print_r($updates); CI_DB_mysql_result Object ( [conn_id] => Resource id #30 [result_id] => Resource id #35 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 5 [row_data] => ) Output of print_r($updates->result_array()); Array ( [0] => Array ( [problem_update_id] => 1 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Some details about a paricular issue [problem_update_active] => 1 ) [1] => Array ( [problem_update_id] => 4 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Another update about the problem with an ID of 3 [problem_update_active] => 1 ) [2] => Array ( [problem_update_id] => 5 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of four [problem_update_active] => 1 ) [3] => Array ( [problem_update_id] => 6 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of 6 [problem_update_active] => 1 ) [4] => Array ( [problem_update_id] => 7 [problem_id] => 3 [problem_update_date] => 2010-10-12 [problem_update_text] => Some new update about the problem with the ID of 3 [problem_update_active] => 1 ) ) 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); } } } 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. 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"]'); 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? 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! 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) {
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.... 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. 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? 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 />"; } } |