Jump to content

Search the Community

Showing results for tags 'array'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. Hi all, New to the forums and hoping someone can be of help here. I'm working with an adaptation of the WeBid Auction system and am pulling data from the auction database to a separate site I'm developing. Basically I am creating a pseudo breadcrumb trail pulling an auction from the database and trying to link it to its category, the parent of that category, the parent of that category and so on for as many levels as required. The auction table structure contains the following of use: id e.g. 5 category e.g. 206 The categories table contains: cat_id e.g. 206 parent_id e.g. 207 level e.g. 1 (anything higher than 1 indicating it's a subcategory) cat_name So basically I'm trying to fetch the auction title then every category level above it linked through cat_id and then parent_id. I hope this makes sense - I'm even pulling my hair out trying to explain such a simple issue! Many thanks, Graham
  2. ${'stats' . $run} = array ( "AP"=>$AP, "EP"=>$EP, "SP"=>$SP, "FX"=>$FX, "Horse"=>$horse, ); $allstats[] = ${'stats' . $run}; I have that running in a while loop to add an array to the main one every time it goes through it. However, my issue is I am trying to assign ranks for each value. Saw horse 1 had AP=51 , EP=47, SP= 32, FX=20. Horse 2 had AP=52, EP = 55, SP=30 and F=19. I am trying to make it print on the screen like so: AP EP SP FX Horse 1 2 2 1 1 Horse 2 1 1 2 2 And etc for however many horses there are. Any ideas or help would be much appreciated. Thanks
  3. Hello, I'm trying to post data to some remote sites and I think I have something in the wrong order. Any help would be appreciated. Thanks for your time. Here is how its suppose to work... gets array of siteurl from sites gets the id of the ads being posted (multiple ids) selects the ad from received checks to see if the url from the ad (received) is the same as one of the siteurl in the array if it is the same then $url2 should equal $info ['url'] if it is not then $url2 should equal 'http://'.$row['siteurl'].'/ads.php?id='.$info ['id'].''; Basically it checks to see which site the original ad was posted from and then when it post back to that site it post the original url, if it post to a different site then it post a different url. Right now it post these results Ad 1 Site 1 http://siteone.com/ads.php?pageid=clickadd&id=1 Site 2 http://sitetwo.com/ads.php?pageid=clickadd&id=1 Site 3 http://sitethree.com/ads.php?pageid=clickadd&id=1 Ad 2 Site 1 http://siteone.com/ads.php?pageid=clickadd&id=2 Site 2 http://sitetwo.com/ads.php?pageid=clickadd&id=2 Site 3 http://sitethree.com/ads.php?pageid=clickadd&id=2 and it should post something like Ad 1 Site 1 http://siteone.com/ads.php?pageid=clickadd&id=1 Site 2 http://someurl.com // because the ad #1 originally came from site #2 Site 3 http://sitethree.com/ads.php?pageid=clickadd&id=1 Ad 2 Site 1 http://siteone.com/ads.php?pageid=clickadd&id=2 Site 2 http://sitetwo.com/ads.php?pageid=clickadd&id=2 Site 3 http://someotherurl.com // because the ad #2 originally came from site #3 foreach($id as $each) { $sql = mysql_query ( "SELECT * FROM receive WHERE id=" . $each ); $info = mysql_fetch_array ( $sql ); // Work out partial data , excluding url for checking and updating ... $wannasay = array ( "id" => $info ['id'], "site" => $info ['site']; // Generate Query string $dataels = array (); foreach ( array_keys ( $wannasay ) as $thiskey ) { array_push ( $dataels, urlencode ( $thiskey ) . "=" . urlencode ( $wannasay [$thiskey] ) ); } $data = implode ( "&", $dataels ); $result = mysql_query("SELECT siteurl FROM sites"); $nodes = array(); $i=0; while ( $row = mysql_fetch_assoc($result) ) { $nodes[] = 'http://'.$row['siteurl'].'/admin/curl.php'; $nodes2[$i] = $row['siteurl']; $i++; // Here is where I have problems foreach( $nodes2 as $value ) { if($value == $info ['site']) { $url2 = $info ['url']; } else $url2 = 'http://'.$row['siteurl'].'/ads.php?id='.$info ['id'].''; } $postfields = $data.'&url=' . $url2; // Update Full query string .. $node_count = count($nodes); $curl_arr = array(); $master = curl_multi_init(); for($i = 0; $i < $node_count; $i++) { $url =$nodes[$i]; $curl_arr[$i] = curl_init($url); curl_setopt($curl_arr[$i], CURLOPT_POST, 1); curl_setopt($curl_arr[$i], CURLOPT_POSTFIELDS, $postfields); curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, 1); curl_multi_add_handle($master, $curl_arr[$i]); } do { curl_multi_exec($master,$running); } while($running > 0); for($i = 0; $i < $node_count; $i++) { $results = curl_multi_getcontent ( $curl_arr[$i] ); echo( "\n" . $results . "\n"); } } }
  4. when i click on image1 with id=1, it stores in session and when i click on image2 with id=2, it stores in session too next to the first one, and when i click on image3 with id=3, it stores in session next to id=2. and so on.... i hope you understand what i am asking .... need help. i know how to get value from array.... like <?php// begin the sessionsession_start(); // create an array$my_array=array('cat', 'dog', 'mouse', 'bird', 'crocodile', 'wombat', 'koala', 'kangaroo'); // put the array in a session variable$_SESSION['animals']=$my_array; // a little message to say we have done itecho 'Putting array into a session variable';// loop through the session array with foreachforeach($_SESSION['animals'] as $key=>$value) { // and print out the values echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />'; }?> /*************************************************************************************************************************************/ but wat i want is, cat ,dog,mouse,bird,crocodile,wombat,koala,kangaroo ... stored in array when i click on them.... i hope you understand.. please help!!! thanks and regards, jazz..
  5. Here are two example of the format of the Arrays, full code and array content in my code below. ARRAY 1 Array ( [version] => 1.0 [injuries] => Array ( [timestamp] => 1377702112 [week] => 1 [injury] => Array ( [0] => Array ( [status] => Questionable [id] => 10009 [details] => Shoulder ) [1] => Array ( [status] => Questionable [id] => 10012 [details] => Ankle ) ARRAY 2 Array ( [version] => 1.0 [players] => Array ( [timestamp] => 1377676937 [player] => Array ( [0] => Array ( [position] => TMDL [name] => Bills, Buffalo [id] => 0251 [team] => BUF ) [1] => Array ( [position] => TMDL [name] => Colts, Indianapolis [id] => 10009 [team] => IND ) What I need to do is sort through both Arrays and finding matching values for the ID key. I need to then combine the values of both arrays into one array so I can print it out on screen. Here is how far I have gotten on this problem: <?php function injuries_report() { //Get json files $injuryData = file_get_contents('http://football.myfantasyleague.com/2013/export?TYPE=injuries&L=&W=&JSON=1&callback='); $playerData = file_get_contents('http://football.myfantasyleague.com/2013/export?TYPE=players&L=&W=&JSON=1'); //format json data into an array $obj1 = json_decode($injuryData, true); $obj2 = json_decode($playerData, true); //return print_r($obj1); //print obj1 to see output return print_r($obj2); //print obj2 to see output } ?> <!--get injuries report --> <pre><?php injuries_report(); ?></pre>
  6. I have a strange problem... I have oscommerce installed and I must modify an array that has 3 values. If I write this code: print_r(array_values($shipping)); print"<hr>"; print_r(array_values($shipping)); print"<hr>"; echo "start<br>"; $elementos_de_array=count($shipping); echo "($elementos_de_array)<br>"; $desdecero=0; while ($desdecero<$elementos_de_array) { echo "$desdecero:".$shipping['$desdecero']."<br>"; $desdecero++; } echo "end<br>"; I receive this in the web: Array ( [0] => shippingpersonalizadodos_shippingpersonalizadodos [1] => Envio a domicilio (Envio a domicilio) [2] => 55 ) start (3) 0: 1: 2: end so... How do I get the values??? Thanks, Francisco
  7. I've got some code that displays a feed from a wordpress xml and it does perfectly on my mamp localhost but when I put it on the windows server everthing just falls apart. <?php $curl = curl_init(); curl_setopt_array($curl, Array( CURLOPT_URL => 'http://blog.thisisfusion.com/feed/', CURLOPT_USERAGENT => 'spider', CURLOPT_TIMEOUT => 120, CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_ENCODING => 'UTF-8' )); $data = curl_exec($curl); curl_close($curl); $xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA); ?> And the loop portion here: <?php $i = 0; foreach ($xml->channel->item as $item) { $creator = $item->children('dc', TRUE); echo '<h2>' . $item->title . '</h2>'; echo '<small>Posted on '. date('l F d, Y', strtotime($item->pubDate)) .' by '.$creator.'</small> </p>'; echo '<p class="description">' . $item->description . '</p>'; if (++$i > 2) break; } ?> It's having a fit on the server saying that THIS section foreach ($xml->channel->item as $item) is trying to get the property of a nonobject and that it's an invalid argument in foreach. If this was truly the case, why is it working on my localhost? I've tried a lot of different methods and I have no clue what to do anymore. I var_dumped and didn't see anything maybe something in $xml is null and I missed it? But I checked to make sure that wasn't the case. I don't know. I would appreciate some help. Thank you.
  8. Please ignore the fact i have a form etc in my class and it submits to the class, what i am stuck on is finding the value from my associative array with the key that passed in the $_POST request. I have looked in the php manual and looked at other fixes people have posted online but something is not right. Easy fix for a seasoned developer i am sure, please help if you have a min. <?php class World { public $world_countries = array( "GB" => "United Kingdom", "US" => "United States", "AF" => "Afghanistan", "AL" => "Albania", "DZ" => "Algeria", "AS" => "American Samoa", "AD" => "Andorra", "AO" => "Angola", "AI" => "Anguilla", "AQ" => "Antarctica", "AG" => "Antigua And Barbuda", "AR" => "Argentina", "AM" => "Armenia", "AW" => "Aruba", "AU" => "Australia", "AT" => "Austria", "AZ" => "Azerbaijan", "BS" => "Bahamas", "BH" => "Bahrain", "BD" => "Bangladesh", "BB" => "Barbados", "BY" => "Belarus", "BE" => "Belgium", "BZ" => "Belize", "BJ" => "Benin", "BM" => "Bermuda", "BT" => "Bhutan", "BO" => "Bolivia", "BA" => "Bosnia And Herzegowina", "BW" => "Botswana", "BV" => "Bouvet Island", "BR" => "Brazil", "IO" => "British Indian Ocean Territory", "BN" => "Brunei Darussalam", "BG" => "Bulgaria", "BF" => "Burkina Faso", "BI" => "Burundi", "KH" => "Cambodia", "CM" => "Cameroon", "CA" => "Canada", "CV" => "Cape Verde", "KY" => "Cayman Islands", "CF" => "Central African Republic", "TD" => "Chad", "CL" => "Chile", "CN" => "China", "CX" => "Christmas Island", "CC" => "Cocos (Keeling) Islands", "CO" => "Colombia", "KM" => "Comoros", "CG" => "Congo", "CD" => "Congo, The Democratic Republic Of The", "CK" => "Cook Islands", "CR" => "Costa Rica", "CI" => "Cote D'Ivoire", "HR" => "Croatia (Local Name: Hrvatska)", "CU" => "Cuba", "CY" => "Cyprus", "CZ" => "Czech Republic", "DK" => "Denmark", "DJ" => "Djibouti", "DM" => "Dominica", "DO" => "Dominican Republic", "TP" => "East Timor", "EC" => "Ecuador", "EG" => "Egypt", "SV" => "El Salvador", "GQ" => "Equatorial Guinea", "ER" => "Eritrea", "EE" => "Estonia", "ET" => "Ethiopia", "FK" => "Falkland Islands (Malvinas)", "FO" => "Faroe Islands", "FJ" => "Fiji", "FI" => "Finland", "FR" => "France", "FX" => "France, Metropolitan", "GF" => "French Guiana", "PF" => "French Polynesia", "TF" => "French Southern Territories", "GA" => "Gabon", "GM" => "Gambia", "GE" => "Georgia", "DE" => "Germany", "GH" => "Ghana", "GI" => "Gibraltar", "GR" => "Greece", "GL" => "Greenland", "GD" => "Grenada", "GP" => "Guadeloupe", "GU" => "Guam", "GT" => "Guatemala", "GN" => "Guinea", "GW" => "Guinea-Bissau", "GY" => "Guyana", "HT" => "Haiti", "HM" => "Heard And Mc Donald Islands", "VA" => "Holy See (Vatican City State)", "HN" => "Honduras", "HK" => "Hong Kong", "HU" => "Hungary", "IS" => "Iceland", "IN" => "India", "ID" => "Indonesia", "IR" => "Iran (Islamic Republic Of)", "IQ" => "Iraq", "IE" => "Ireland", "IL" => "Israel", "IT" => "Italy", "JM" => "Jamaica", "JP" => "Japan", "JO" => "Jordan", "KZ" => "Kazakhstan", "KE" => "Kenya", "KI" => "Kiribati", "KP" => "Korea, Democratic People's Republic Of", "KR" => "Korea, Republic Of", "KW" => "Kuwait", "KG" => "Kyrgyzstan", "LA" => "Lao People's Democratic Republic", "LV" => "Latvia", "LB" => "Lebanon", "LS" => "Lesotho", "LR" => "Liberia", "LY" => "Libyan Arab Jamahiriya", "LI" => "Liechtenstein", "LT" => "Lithuania", "LU" => "Luxembourg", "MO" => "Macau", "MK" => "Macedonia, Former Yugoslav Republic Of", "MG" => "Madagascar", "MW" => "Malawi", "MY" => "Malaysia", "MV" => "Maldives", "ML" => "Mali", "MT" => "Malta", "MH" => "Marshall Islands", "MQ" => "Martinique", "MR" => "Mauritania", "MU" => "Mauritius", "YT" => "Mayotte", "MX" => "Mexico", "FM" => "Micronesia, Federated States Of", "MD" => "Moldova, Republic Of", "MC" => "Monaco", "MN" => "Mongolia", "MS" => "Montserrat", "MA" => "Morocco", "MZ" => "Mozambique", "MM" => "Myanmar", "NA" => "Namibia", "NR" => "Nauru", "NP" => "Nepal", "NL" => "Netherlands", "AN" => "Netherlands Antilles", "NC" => "New Caledonia", "NZ" => "New Zealand", "NI" => "Nicaragua", "NE" => "Niger", "NG" => "Nigeria", "NU" => "Niue", "NF" => "Norfolk Island", "MP" => "Northern Mariana Islands", "NO" => "Norway", "OM" => "Oman", "PK" => "Pakistan", "PW" => "Palau", "PA" => "Panama", "PG" => "Papua New Guinea", "PY" => "Paraguay", "PE" => "Peru", "PH" => "Philippines", "PN" => "Pitcairn", "PL" => "Poland", "PT" => "Portugal", "PR" => "Puerto Rico", "QA" => "Qatar", "RE" => "Reunion", "RO" => "Romania", "RU" => "Russian Federation", "RW" => "Rwanda", "KN" => "Saint Kitts And Nevis", "LC" => "Saint Lucia", "VC" => "Saint Vincent And The Grenadines", "WS" => "Samoa", "SM" => "San Marino", "ST" => "Sao Tome And Principe", "SA" => "Saudi Arabia", "SN" => "Senegal", "SC" => "Seychelles", "SL" => "Sierra Leone", "SG" => "Singapore", "SK" => "Slovakia (Slovak Republic)", "SI" => "Slovenia", "SB" => "Solomon Islands", "SO" => "Somalia", "ZA" => "South Africa", "GS" => "South Georgia, South Sandwich Islands", "ES" => "Spain", "LK" => "Sri Lanka", "SH" => "St. Helena", "PM" => "St. Pierre And Miquelon", "SD" => "Sudan", "SR" => "Suriname", "SJ" => "Svalbard And Jan Mayen Islands", "SZ" => "Swaziland", "SE" => "Sweden", "CH" => "Switzerland", "SY" => "Syrian Arab Republic", "TW" => "Taiwan", "TJ" => "Tajikistan", "TZ" => "Tanzania, United Republic Of", "TH" => "Thailand", "TG" => "Togo", "TK" => "Tokelau", "TO" => "Tonga", "TT" => "Trinidad And Tobago", "TN" => "Tunisia", "TR" => "Turkey", "TM" => "Turkmenistan", "TC" => "Turks And Caicos Islands", "TV" => "Tuvalu", "UG" => "Uganda", "UA" => "Ukraine", "AE" => "United Arab Emirates", "UM" => "United States Minor Outlying Islands", "UY" => "Uruguay", "UZ" => "Uzbekistan", "VU" => "Vanuatu", "VE" => "Venezuela", "VN" => "Viet Nam", "VG" => "Virgin Islands (British)", "VI" => "Virgin Islands (U.S.)", "WF" => "Wallis And Futuna Islands", "EH" => "Western Sahara", "YE" => "Yemen", "YU" => "Yugoslavia", "ZM" => "Zambia", "ZW" => "Zimbabwe" ); public function display_countries() { asort($this->world_countriess); foreach ($this->world_countries as $key => $value) { echo $key . ' > <a target="_blank" href="https://www.google.se/?gws_rd=cr#fp=bac353e51a633d27&q=' . $value . '">' . $value . '</a><br>'; } } public function eeti_world_options($args) { asort($this->world_countries); $outout = '<select name="country">'; foreach ($this->world_countries as $key => $value) { if ($this->$value == $args) { $outout .= '<option value="' . $key . '" selected>' . $value . '</option>'; } else { $outout .= '<option value="' . $key . '">' . $value . '</option>'; } } $outout .= '</select>'; return $outout; } } ?> <?php $world = new World(); if (isset($_POST['submit'])) { } ?> <form method="post" action="class-world.php"> <?php echo $world->eeti_world_options('Uganda'); ?> <input type="submit" name="submit"> </form>
  9. I'm looking for a way to remove all but the last 10 elements in an array. Is it possible to do this with array_splice? I have an array with greater than 1000 elements and I don't want to have to specify each element I want to remove. It would be cool if I could do something like "remove elements 1-990".
  10. I have a function which enables me to obtain values from a database: function fetch_user_lists($user_id, $list_title_id) { $conn = db_connect(); $query = "select * from user_lists where user_id='$user_id' and list_title_id='$list_title_id'"; $result = @mysql_query($query); if (!$result) return false; $num_cats = @mysql_num_rows($result); if ($num_cats ==0) return false; $result = db_result_to_array($result); return $result; } Currently I'm able to obtain values I'm looking for via the following: $user_lists = fetch_user_lists($user_id, $list_title_id); if (is_array($user_lists)) { foreach ($user_lists as $row) { $list_meta = $row['list_meta']; $content = $row['content']; if ($list_meta == 'list_title') { echo $content; } } } I was wondering... is there a function/command that might allow me to search for a value within an array without having go extract the array row by row, effectively saying "if you've found the result I'm looking for, do this" ? Any help appreciated! Simon
  11. The following serialized string is being pulled from the meta data of a Woocommerce product. a:2:{s:17:"set_51fb76f97cc57";a:6:{s:15:"conditions_type";s:3:"all";s:10:"conditions";a:1:{i:1;a:2:{s:4:"type";s:8:"apply_to";s:4:"args";a:2:{s:10:"applies_to";s:5:"roles";s:5:"roles";a:1:{i:0;s:14:"trade_customer";}}}}s:9:"collector";a:1:{s:4:"type";s:7:"product";}s:4:"mode";s:5:"block";s:5:"rules";a:1:{i:1;a:4:{s:4:"from";s:0:"";s:2:"to";s:0:"";s:4:"type";s:14:"price_discount";s:6:"amount";s:0:"";}}s:10:"blockrules";a:1:{i:1;a:5:{s:4:"from";s:1:"*";s:6:"adjust";s:1:"1";s:4:"type";s:16:"fixed_adjustment";s:6:"amount";s:4:"8.37";s:9:"repeating";s:3:"yes";}}}s:17:"set_51fb76f97d6a2";a:6:{s:15:"conditions_type";s:3:"all";s:10:"conditions";a:1:{i:1;a:2:{s:4:"type";s:8:"apply_to";s:4:"args";a:2:{s:10:"applies_to";s:5:"roles";s:5:"roles";a:1:{i:0;s:19:"bulk_trade_customer";}}}}s:9:"collector";a:1:{s:4:"type";s:7:"product";}s:4:"mode";s:5:"block";s:5:"rules";a:1:{i:1;a:4:{s:4:"from";s:0:"";s:2:"to";s:0:"";s:4:"type";s:14:"price_discount";s:6:"amount";s:0:"";}}s:10:"blockrules";a:1:{i:1;a:5:{s:4:"from";s:1:"*";s:6:"adjust";s:1:"1";s:4:"type";s:16:"fixed_adjustment";s:6:"amount";s:5:"9.428";s:9:"repeating";s:3:"yes";}}}} I also have this function which I am writing in order to pull out the variable product data and display it on the site: function mi_price_adjust(){ global $post, $current_user, $user_roles; $meta = get_post_meta($post->ID); $curPrice = (float)$meta['_regular_price'][0]; $variations = unserialize($meta['_pricing_rules'][0]); $user_roles = $current_user->roles; $theRoll = ''; $thePrice = $curPrice; foreach($user_roles as $miroll){ if(in_array($miroll, $user_roles)){ $theRoll = $miroll; } } if($theRoll != ''){ foreach($variations as $curvar){ $var_roll = $curvar['conditions'][1]['args']['roles'][0]; $var_cost = (float)$curvar['blockrules'][1]['amount']; if($var_roll == $theRoll){ $thePrice = $curPrice - $var_cost; } } } if($thePrice != $curPrice){ return "<strike>".$curPrice."</strike><br /><span class=\"youpayText\">You pay £$thePrice</span>"; }else{ return $thePrice; } } Everything is working fine apart from one thing. I am getting the following error: Invalid argument supplied for foreach The line in question is foreach($variations as $curvar){ And the $variations variable is being populated using this: $variations = unserialize($meta['_pricing_rules'][0]); Which returns the serialized string at the top of this post. Can anyone shed any light on why this might be happening and what we might be able to do to either fix it or circumvent it?
  12. Hi, I am not very good at PHP however I am trying to edit a php function for Magento. $categoryID = $this->getCategoryId(); //the value is like 7,3,6,9 $cats = explode(',', $categoryID); $collection = Mage::getModel('catalog/product') ->getCollection() ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') ->addAttributeToSelect('*') ->addAttributeToFilter('category_id', array( array('finset' => '7'), array('finset' => '3'), array('finset' => '6'), array('finset' => '9') ) ); I want to generate the below part automatically based on the value(s) of $cats array('finset' => '7'), array('finset' => '3'), array('finset' => '6'), array('finset' => '9') How can I do it, urgent help will be extremely appreciated. Thanks in advance
  13. I am trying to figure out how to check an array for consecutive numbers and then copy the ones that arent consecutive to a new array. To make things a little more difficult the keys arent strictly numbered there are letters in front of them. Any ideas? var1 = array("PK100","PK101","PK102","PK110","PK120") should be separated into var2 = array("PK100","PK101","PK102") var3 = array("PK110","PK120") or var2 = array("PK100","PK101","PK102") var3 = array("PK110") var4 = array("PK120")
  14. Hello, I am trying to create an array where by the items listed are nested with the names and the array spat out is easy to use when I am creating an ajax function with data from it all. Below is an idea of what I need to do: # This is where I am grabbing the data from the instagram class $data_url[] = $data->images->standard_resolution->url; $data_link[] = $data->link; $data_id[] = $data->getId(); $data_likes[] = $data->likes->count; {["images":[ ["data_url":[ ["http:\/\/distilleryimage4.s3.amazonaws.com\/f8e5e2fafe8811e2a42922000a9e51c4_7.jpg"] ], ["data_link":[ ["http:\/\/instagram.com\/p\/cq2pjLMNNE\/"] ], ["data_id": [516465457066201924_288233123] ], ["data_likes": [18] ] ] ] } In my current ajax.php page, I am creating a place where data can be captured and I can use it to get the images and place them into a page. Here is what I have got so far: $instagram = new Instagram\Instagram; $instagram->setAccessToken($_SESSION['instagram_access_token']); $token = $_SESSION['instagram_access_token']; //$clientID = $_SESSION['client_id']; $current_user = $instagram->getCurrentUser(); $tag = $instagram->getTag('folkclothing'); $media = $tag->getMedia(isset($_GET['max_tag_id']) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null); /* $params = isset( $_GET['max_tag_id'] ) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null; */ /* $media = $tag->getMedia($params); */ /* $next_page = $media->getNext(); */ /* // Receive new data $imageMedia = $instagram->pagination($media); */ // Collect everything for json output $images = array(); $data_link = array(); $data_id = array(); $data_likes = array(); foreach ($media as $data) { $images[] = array($data_url[] = $data->images->standard_resolution->url,$data_link[] = $data->link, $data_id[] = $data->getId(), $data_likes[] = $data->likes->count); } echo json_encode(array( 'next_id' => $media->getNextMaxTagId(), 'images' => $images )); Below is what my /ajax/ url gives me: {"next_id":"1374887530845","images":[["http:\/\/distilleryimage4.s3.amazonaws.com\/f8e5e2fafe8811e2a42922000a9e51c4_7.jpg","http:\/\/instagram.com\/p\/cq2pjLMNNE\/","516465457066201924_288233123",18],["http:\/\/distilleryimage10.s3.amazonaws.com\/46f790e0fdaf11e29de622000ae90e7b_7.jpg","http:\/\/instagram.com\/p\/coEUD0MyGO\/","515681128006492558_197168271",23],["http:\/\/distilleryimage6.s3.amazonaws.com\/7e510fa6fcee11e29a4b22000a1fb593_7.jpg","http:\/\/instagram.com\/p\/clmYo1AgU6\/","514986551277651258_20025128",25],["http:\/\/distilleryimage0.s3.amazonaws.com\/4f41be96fc3411e2829822000a9f1487_7.jpg","http:\/\/instagram.com\/p\/cjN3PipYkE\/","514315753313634564_190097401",10],["http:\/\/distilleryimage0.s3.amazonaws.com\/bcc8d83cfb9911e2921e22000aa81fd0_7.jpg","http:\/\/instagram.com\/p\/chPPNdGDhI\/","513758848433535048_6206549",13],["http:\/\/distilleryimage2.s3.amazonaws.com\/ef97af2efb5611e2b16122000a1f9e61_7.jpg","http:\/\/instagram.com\/p\/cgYg4ljpby\/","513518170419402482_52465932",1],["http:\/\/distilleryimage5.s3.amazonaws.com\/8e7bbf04fa9e11e2aea022000a9d0ee7_7.jpg","http:\/\/instagram.com\/p\/ceBeGXNpA9\/","512853874029531197_20203491",2],["http:\/\/distilleryimage4.s3.amazonaws.com\/96dc4444f9f811e2b88d22000a1fd1dd_7.jpg","http:\/\/instagram.com\/p\/cb5gooAgW4\/","512255913931965880_20025128",6],["http:\/\/distilleryimage11.s3.amazonaws.com\/6b80e884f9dc11e29b2522000a9f13d5_7.jpg","http:\/\/instagram.com\/p\/cbibv3JW9H\/","512154423034998599_430907394",20],["http:\/\/distilleryimage7.s3.amazonaws.com\/64f82bd6f95411e2a73522000a1faf50_7.jpg","http:\/\/instagram.com\/p\/cZzAF8syFb\/","511664339442409819_197168271",16],["http:\/\/distilleryimage10.s3.amazonaws.com\/b54645f4f93711e283e622000a1fb86d_7.jpg","http:\/\/instagram.com\/p\/cZbgGrlSzW\/","511560986135964886_187431354",17],["http:\/\/distilleryimage8.s3.amazonaws.com\/a9fc18a2f87111e29c8b22000a9f18f4_7.jpg","http:\/\/instagram.com\/p\/cW5Q5CBrlw\/","510847457153169776_378485429",6],["http:\/\/distilleryimage0.s3.amazonaws.com\/55b6269cf86311e2b5f422000a1f9a34_7.jpg","http:\/\/instagram.com\/p\/cWthoKit5E\/","510795830715407940_203990694",16],["http:\/\/distilleryimage9.s3.amazonaws.com\/bff691e2f82a11e2939b22000a1f9251_7.jpg","http:\/\/instagram.com\/p\/cV_K8mBu9R\/","510591961963884369_256035442",12],["http:\/\/distilleryimage4.s3.amazonaws.com\/5ef4c3c0f73811e2890322000a9e48f1_7.jpg","http:\/\/instagram.com\/p\/cS4nTwwE_U\/","509718699729506260_37194114",34],["http:\/\/distilleryimage8.s3.amazonaws.com\/a1b5f0acf6cb11e2957722000a1f9a39_7.jpg","http:\/\/instagram.com\/p\/cRfiPgmAWQ\/","509326925426591120_453101536",11],["http:\/\/distilleryimage6.s3.amazonaws.com\/4bf62240f68511e29aee22000a9f38e6_7.jpg","http:\/\/instagram.com\/p\/cQl6qiBzdu\/","509073517011482478_5670460",223],["http:\/\/distilleryimage1.s3.amazonaws.com\/d23848d6f61e11e2807c22000a9e06c7_7.jpg","http:\/\/instagram.com\/p\/cPR9_otpGt\/","508704309923713453_20203491",6]]} Can anyone guide me into the best way I can do this so it gives me an array from my ajax.php so I can grab the data and place it into my page better? I have tried numerous techniques but they have not worked at all. Thanks, Mark
  15. Hi guys, I'm quite new to php - I've made forms before but not come across having to make checkbox options appear in email. I've searched the forum and have found similar posts but none of the answers have worked for me as I think it's the way I've written my code. What happens currently is when the form is emailed the "help" option just says Array. What I want it to do is give me multiple answers if the user has clicked more than one checkbox. - I think i'm close but just missing the php code and now I'm going round in circles. here is my html for the section I need to get working (checkboxes): <input type="checkbox" name="help" id="acting" value="Acting">Acting<br> <input type="checkbox" name="help[]" id="singing" value="Singing">Singing <br /> <input type="checkbox" name="help[]" id="dancing" value="Dancing">Dancing <br /> <input type="checkbox" name="help[]" id="general_advice" value="General Advice">General Advice And here is my PHP (in full) <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "email@email.com"; $email_subject = "New"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form your submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['location']) || !isset($_POST['help']) || !isset($_POST['considering']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form your submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // required $location = $_POST['location']; // required $comments = $_POST['comments']; // required $help = $_POST['help']; // required $considering = $_POST['considering']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = " ---------------------------------- FORM DETAILS BELOW ---------------------------------- \n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)." \n"; $email_message .= "Email: ".clean_string($email_from)." \n"; $email_message .= "Telephone: ".clean_string($telephone)." \n"; $email_message .= "Location: ".clean_string($location)." \n"; $email_message .= "I need help with: ".clean_string($help)." \n"; $email_message .= "I am considering: ".clean_string($considering)." \n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ;} ?> Any help would be greatly appreciated. Thanks
  16. Hello everyone.I am learning arrays in PHP.I tried to take 6 text inputs and store it ina a array and then display when we click submit button.But I am not getting output.Below is my code.Please help me out. <html> <head> <title> List Function </title> </head> <body> <?php if(isset($_POST['posted'])) { for($count=0;$count<=5;$count++) { $a = $_POST['hidden'][$count]; echo "$a<br/>"; } } ?> <form method = "POST" action = "listfunction.php"> <input type = "hidden" name = "posted" value = "true"/> <?php for($counter=0;$counter<=5;$counter++) { echo "<input type = 'text' name = '$array[$counter]'><br/>"; echo "<input type = 'hidden' name = 'hidden[]' value = '$array[$counter]'>"; } ?> <input type = "submit" value = "submit"/> </body> </html> Thank you.
  17. I've been trying to learn PHP with the PHP Solutions book second editions by David Powers. I seemingly can't find anyway of contacting him about the code I found in the book. <?php foreach ($_POST as $key => $value) { // assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); // if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { $missing[] = $key; } elseif (in_array($key, $expected)) { // otherwise, assign to a variable of the same name as $key ${$key} = $temp; } } I understand that is_array checks whether or not $value is an array but I can't find a scenario in which it would be array and therefore why it would be there at all. Also I the last part relies on the fact above which I don't understand as well.
  18. Hi, I'm trying to turn input from textarea into an array here is what the textarea input look like [input 1] [input 2] [input 3] I'm trying to split everything inside the square bracket "[]" into an array. here are my codes $option = array(); $regex = "#[\[^]]*#s"; $input = "[input 1] [input 2] [input 3]"; $option = preg_split($regex, $input, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); the output is Array ( [0] => input 1] [1] => input 2] [2] => input 3] ) the closing bracket still there, So what am I missing in the regex pattern? Thanks
  19. I'm looking to sort this multidimensional array according to its integer value under the key name 'rank'. In other words $r_set contains the combined results of a number of search engines and each result is assigned a 'rank' according to which I want the array to be sorted. $r_set contents look like this -> $google[$google_count] = array ('url'=>$item->link, 'url_title'=>$item->title, 'snippet' =>$item->htmlSnippet, 'rank' => 100-$google_count, 'engine' => 'Google'); $google_count++; I load a number of these kinds of results(.ie $google[google_count] and others like it) in to $r_set when they have the same structure. I want $r_set to be sorted by its 'rank' key starting highest to lowest.
  20. This is the var_dump of a json_decode function. How do I parse it with a foreach and load it in to an array? object(stdClass)#1 (2) { ["noun"]=> object(stdClass)#2 (1) { ["syn"]=> array(39) { [0]=> string(12) "domestic dog" [1]=> string(16) "Canis familiaris" [2]=> string(5) "frump" [3]=> string(3) "cad" [4]=> string(7) "bounder" [5]=> string(10) "blackguard" [6]=> string(5) "hound" [7]=> string(4) "heel" [8]=> string(5) "frank" [9]=> string(11) "frankfurter" [10]=> string(6) "hotdog" [11]=> string(7) "hot dog" [12]=> string(6) "wiener" [13]=> string(11) "wienerwurst" [14]=> string(6) "weenie" [15]=> string(4) "pawl" [16]=> string(6) "detent" [17]=> string(5) "click" [18]=> string(7) "andiron" [19]=> string(7) "firedog" [20]=> string( "dog-iron" [21]=> string( "blighter" [22]=> string(5) "canid" [23]=> string(6) "canine" [24]=> string(5) "catch" [25]=> string(4) "chap" [26]=> string(4) "cuss" [27]=> string(18) "disagreeable woman" [28]=> string(5) "fella" [29]=> string(6) "feller" [30]=> string(6) "fellow" [31]=> string(4) "gent" [32]=> string(3) "lad" [33]=> string(7) "sausage" [34]=> string(9) "scoundrel" [35]=> string(4) "stop" [36]=> string(7) "support" [37]=> string(16) "unpleasant woman" [38]=> string(7) "villain" } } ["verb"]=> object(stdClass)#3 (2) { ["syn"]=> array(10) { [0]=> string(5) "chase" [1]=> string(11) "chase after" [2]=> string(5) "trail" [3]=> string(4) "tail" [4]=> string(3) "tag" [5]=> string(10) "give chase" [6]=> string( "go after" [7]=> string(5) "track" [8]=> string(6) "follow" [9]=> string(6) "pursue" } ["rel"]=> array(2) { [0]=> string(10) "chase away" [1]=> string(9) "tag along" } } } if ($_POST['query']) { $word = ($_POST['query']); $fullquery = 'http://words.bighugelabs.com/api/2/2b1ae894d9e4acd1517b457666fc9431/'.$word.'/json'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $fullquery); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data=curl_exec($ch); $js = json_decode($data); var_dump($js); $ob_c=0; foreach ($js -> noun as $object[$ob_c]) { echo $object[$ob_c].'<br>'; $ob_c++; } }
  21. I have this array: <?php $continents=array("Asia"=>array("Bangladesh","India","Pakistan"), "Europe"=>array("England","France"), "Africa"=>array("Kenya","Libya","Somalia")); ?> Now I would like to echo: In Africa there are: Kenya, Libya, Somalia. How can I do that? Can anyone please help me? Thanks in advance.
  22. I'f I do a var_dump after taking in the array from the foreach statement then all of the variables are present. However, by the time the variables go through the switch statement and we run the first case it only prints out the URL for most of the results and URL_title for others. foreach ($js -> results as $item) { $Faroo[$o] = array ('url'=>$item->url, 'url_title'=>$item->title, 'snippet' =>$item->kwic, 'rank' => 100-$o, 'engine' => 'Faroo'); //var_dump($Faroo[$o]); $o++; } $s=$s+10; $e=$e+10; } } ?> <?php $agg = $_POST['agg']; $full_count=0; switch ($agg) { case 'Aggregated': while ($full_count<=$bing_count) //while m <= bing results m = 0; { $r_set[$full_count] = $bing_results[$full_count]; //load bing[m] in to r_set[m] $full_count++; //m = increments for every bing result } $b_count=0; $r_count=0; //reset b_count so we can start again and create r_count so we can loop through the existing unilist while ($b_count<$blekko_count) // 0 < blekko { // We reset postion in while ( $Blekko[$b_count]['url']!=$r_set[$r_count]['url']) { //check that the url is not already in the list $r_count++; //increment z to loop through the full r_set if ($r_count>$full_count) //When r_count counts through the full_count break (after finding all the matches)//should that not be b_count? { break; } } if ( $Blekko[$b_count]['url'] == $r_set[$r_count]['url']) { //if it is in the list then add the score $r_set[$r_count]['rank']+=$Blekko[$b_count]['rank']; $b_count++; //move to next element } else { //if not in the list then add it $full_count++; //y is used to increment on from this point $r_set[$full_count]=$Blekko[$b_count]; $b_count++; //if r_count is not larger then full count and url's do not match then we increment b_count } } $b_count=0; $r_count=0; //reset both counters again while ($b_count<$o) { // We reset postion in while ( $Faroo[$b_count]['url']!=$r_set[$r_count]['url']) { //check that the url is not already in the list $r_count++; if ($r_count>$full_count) { break; } } if ( $Faroo[$b_count]['url'] == $r_set[$r_count]['url']) { //if it is in the list then add the score $r_set['rank'][$r_count]+=$Faroo[$b_count]['rank']; $b_count++; //move to next element } else { //if not in the list then add it $full_count++; //y is used to increment on from this point $r_set[$full_count]= $Faroo[$b_count]; $b_count++; } } echo $full_count; array_multisort($r_set, SORT_ASC, 'rank'); //not sure if this works or not yet $echo_l = 0; while ($echo_l<=$full_count) { echo 'URL: '.$r_set[$echo_l]['url'].'<br>'; echo 'URL TITLE: '.$r_set[$echo_l]['url_title'].'<br>'; echo 'SNIPPET: '.$r_set[echo_l]['snippet'].'<br>'; echo 'RANK: '.$r_set[echo_l]['rank'].'<br>'; echo 'ENGINE: '.$r_set[echo_l]['engine'].'<br>'; var_dump($Blekko[$echo_l]); $echo_l++; }
  23. I have an array containing the users input of 14 strings, I want to search this array to find duplicates, but I'm not sure how to go about it efficiently... there isn't already a function that does this by any chance is there? Thanks
  24. Fatal error: Cannot use string offset as an array in /..../ on line 6 { $bing_results[$b] = array ('url' => $value->Url, 'title' => $value->Title, 'snippet' => $value->Description, 'rank' => 100-$b); echo 'Lets see? : '.$bing_results[$b]['url']['title']['snippet']['rank']; $b++; }
  25. Greetings all, I have a script that creates an array from a folder of images. // Create Array $files = array(); if( is_dir( $thumbs_dir ) ) { if( $handle = opendir( $thumbs_dir ) ) { while( ( $file = readdir( $handle ) ) !== false ) { if( $file != "." && $file != ".." ) { array_push( $files, $file ); } } closedir( $handle ); } } If I echo this array out into a table or what have you it lists them in a strange way. 4_Photo1.jpg 4_Photo11.jpg 4_Photo12.jpg ......and so on up to 19 4_Photo2.jpg 4_Photo21.jpg 4_Photo22.jpg .....and so on up to 29 4_Photo3.jpg 4_Photo31.jpg 4_Photo32.jpg As you can see the array comes out in, well, a numeric order but a weird one. Instead of loading 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, it loads like above 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 21, 22..... How can I go about sorting this so that it comes out how one would count normally? Preferably in reverse order, counting down would be better. I tried: sort( $files, SORT_NUMERIC ); But that got really messy and threw the order all over the place. Best Regards, Nightasy
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.