2017-04-19 1 views
-1

ich den folgenden Code in PHP geschrieben habenWie die Werte eines assoziativen Arrays Daten in einem anderen Array verfeinern

include '../../cloudinary/Cloudinary.php'; 
include '../../cloudinary/Uploader.php'; 

\Cloudinary::config(array 
(
    "cloud_name" => "cloud_name", 
    "api_key" => "api_key", 
    "api_secret" => "some_key" 
)); 

foreach ($_FILES["img"]["tmp_name"] as $array_number => $holding_value) 
{ 
    $date = getTime(); 
    $tmp_img_name = $_SESSION["username"].$count.$date["timestamp"]."."."jpg"; 

    //store image to temporary location 
    if(move_uploaded_file($holding_value, $temp."/".$tmp_img_name)) 
     { 
      $mainimage[] = \Cloudinary\Uploader::upload($temp."/".$tmp_img_name, $options = array('folder' => 'original')); 

      for($i=0; $i<3; $i++) 
       { 
        //read image 
        $resize = new ResizeImage($temp."/".$tmp_img_name); 
        //resize to desire format 
        $resize->resizeTo($image_widths[$i], $image_heights[$i], 'exact'); 
        //store after resizing 
        $resize->saveImage($store_paths[$i]."/".$tmp_img_name); 

        if($i == 0) 
         { 
          $thumb1[] = \Cloudinary\Uploader::upload($store_paths[$i]."/".$tmp_img_name, $options = array('folder' => 'thumbnail_100x141')); 
          unlink($store_paths[$i]."/".$tmp_img_name); 
         } 

        if($i == 1) 
         { 
          $thumb2[] = \Cloudinary\Uploader::upload($store_paths[$i]."/".$tmp_img_name, $options = array('folder' => 'average_300x424')); 
          unlink($store_paths[$i]."/".$tmp_img_name); 
         } 

        if($i == 2) 
         { 
          $thumb3[] = \Cloudinary\Uploader::upload($store_paths[$i]."/".$tmp_img_name, $options = array('folder' => 'original_compressed_700x990')); 
          unlink($store_paths[$i]."/".$tmp_img_name); 
         } 
       } 
     } 

    $count ++; 
    unlink($temp."/".$tmp_img_name); 
} 

nach einer print_r() von folgenden Variablen =>$mainimage tun, $thumb1, $thumb2, $thumb3 i erhalten die folgenden Ausgabe

// Hauptoriginalbildarray

Array 
(
[0] => Array 
    (
     [public_id] => some_public_id 
     [version] => 1492583096 
     [signature] => some_signature 
     [width] => 461 
     [height] => 358 
     [format] => jpg 
     [resource_type] => image 
     [created_at] => 2017-04-19T06:24:56Z 
     [tags] => Array 
      (
      ) 

     [bytes] => 25954 
     [type] => upload 
     [etag] => 589bded2f63f2643503074989ec74dc6 
     [url] => some_url 
     [secure_url] => some_secure_url 
     [original_filename] => some_original_filename 
    ) 

[1] => Array 
    (
     [public_id] => some_public_id 
     [version] => 1492583115 
     [signature] => some_signature 
     [width] => 320 
     [height] => 320 
     [format] => jpg 
     [resource_type] => image 
     [created_at] => 2017-04-19T06:25:15Z 
     [tags] => Array 
      (
      ) 

     [bytes] => 15940 
     [type] => upload 
     [etag] => 9beb81ac72ace5e176d80086b97eeb13 
     [url] => some_url 
     [secure_url] => some_secure_url 
     [original_filename] => some_original_filename 
    ) 

[2] => Array 
    (
     [public_id] => some_public_id 
     [version] => 1492583134 
     [signature] => some_signature 
     [width] => 531 
     [height] => 315 
     [format] => jpg 
     [resource_type] => image 
     [created_at] => 2017-04-19T06:25:34Z 
     [tags] => Array 
      (
      ) 

     [bytes] => 18449 
     [type] => upload 
     [etag] => 0b8f33226b89b26655d00d7b8d04971e 
     [url] => some_url 
     [secure_url] => some_secure_url 
     [original_filename] => some_original_filename 
    ) 

)

// thumb1 Bildarray

Array 
(
[0] => Array 
    (
     [public_id] => some_public_id 
     [version] => 1492583099 
     [signature] => some_signature 
     [width] => 100 
     [height] => 141 
     [format] => jpg 
     [resource_type] => image 
     [created_at] => 2017-04-19T06:24:59Z 
     [tags] => Array 
      (
      ) 

     [bytes] => 14101 
     [type] => upload 
     [etag] => 1f13b4f8b152a3015700b5e1a8cd0c7c 
     [url] => some_url 
     [secure_url] => some_secure_url 
     [original_filename] => some_original_filename 
    ) 

[1] => Array 
    (
     [public_id] => some_public_id 
     [version] => 1492583119 
     [signature] => some_signature 
     [width] => 100 
     [height] => 141 
     [format] => jpg 
     [resource_type] => image 
     [created_at] => 2017-04-19T06:25:19Z 
     [tags] => Array 
      (
      ) 

     [bytes] => 14050 
     [type] => upload 
     [etag] => 816dec6dd5b611c8f85e25e8172b3092 
     [url] => some_url 
     [secure_url] => some_secure_url 
     [original_filename] => some_original_filename 
    ) 

[2] => Array 
    (
     [public_id] => some_public_id 
     [version] => 1492583138 
     [signature] => some_signature 
     [width] => 100 
     [height] => 141 
     [format] => jpg 
     [resource_type] => image 
     [created_at] => 2017-04-19T06:25:38Z 
     [tags] => Array 
      (
      ) 

     [bytes] => 11379 
     [type] => upload 
     [etag] => 98f9228b60c2f2bf9734e1c6ae729e47 
     [url] => some_url 
     [secure_url] => some_secure_url 
     [original_filename] => some_original_filename 
    ) 

)

// thumb2 Bildarray

Array 
(
[0] => Array 
    (
     [public_id] => some_public_id 
     [version] => 1492583104 
     [signature] => some_signature 
     [width] => 300 
     [height] => 424 
     [format] => jpg 
     [resource_type] => image 
     [created_at] => 2017-04-19T06:25:04Z 
     [tags] => Array 
      (
      ) 

     [bytes] => 77276 
     [type] => upload 
     [etag] => 26dc8f2d766ca830292d13612688e264 
     [url] => some_url 
     [secure_url] => some_secure_url 
     [original_filename] => some_original_filename 
    ) 

[1] => Array 
    (
     [public_id] => some_public_id 
     [version] => 1492583123 
     [signature] => some_signature 
     [width] => 300 
     [height] => 424 
     [format] => jpg 
     [resource_type] => image 
     [created_at] => 2017-04-19T06:25:23Z 
     [tags] => Array 
      (
      ) 

     [bytes] => 73831 
     [type] => upload 
     [etag] => f0fc538ba3afaabcb72fda891361834a 
     [url] => some_url 
     [secure_url] => some_secure_url 
     [original_filename] => some_original_filename 
    ) 

[2] => Array 
    (
     [public_id] => some_public_id 
     [version] => 1492583143 
     [signature] => some_signature 
     [width] => 300 
     [height] => 424 
     [format] => jpg 
     [resource_type] => image 
     [created_at] => 2017-04-19T06:25:43Z 
     [tags] => Array 
      (
      ) 

     [bytes] => 67627 
     [type] => upload 
     [etag] => a039768e2ac21671317c5867ec3f5671 
     [url] => some_url 
     [secure_url] => some_secure_url 
     [original_filename] => some_original_filename 
    ) 

)

// thumb3 Bildarray

Array 
(
[0] => Array 
    (
     [public_id] => some_public_id 
     [version] => 1492583111 
     [signature] => some_signature 
     [width] => 700 
     [height] => 990 
     [format] => jpg 
     [resource_type] => image 
     [created_at] => 2017-04-19T06:25:11Z 
     [tags] => Array 
      (
      ) 

     [bytes] => 298594 
     [type] => upload 
     [etag] => 26d2f4ece088bc30bcb02535ef8f9bc8 
     [url] => some_urlh1axjsxkt4dpgog25kfq.jpg 
     [secure_url] => some_secure_url 
     [original_filename] => some_original_filename 
    ) 

[1] => Array 
    (
     [public_id] => some_public_id 
     [version] => 1492583130 
     [signature] => some_signature 
     [width] => 700 
     [height] => 990 
     [format] => jpg 
     [resource_type] => image 
     [created_at] => 2017-04-19T06:25:30Z 
     [tags] => Array 
      (
      ) 

     [bytes] => 301400 
     [type] => upload 
     [etag] => 96913a8659a22a459c049b47b8862d80 
     [url] => some_urlz9ciicghziugi9nckzug.jpg 
     [secure_url] => some_secure_url 
     [original_filename] => some_original_filename 
    ) 

[2] => Array 
    (
     [public_id] => some_public_id 
     [version] => 1492583150 
     [signature] => some_signature 
     [width] => 700 
     [height] => 990 
     [format] => jpg 
     [resource_type] => image 
     [created_at] => 2017-04-19T06:25:50Z 
     [tags] => Array 
      (
      ) 

     [bytes] => 285431 
     [type] => upload 
     [etag] => 42a605e4916a6073b5e7b50a66dbcd37 
     [url] => some_urlbxocbgwgp98nzozekj4f.jpg 
     [secure_url] => some_secure_url 
     [original_filename] => some_original_filename 
    ) 
) 

Was ich tun möchte, ist i 4 neue Array Variablen machen machen dem Namen =>$pic1 = $pic2 = $pic3 = array();

Ich möchte alle speichern die array[0] Werte in $pic1 alle array[1] Werte in $pic2 & alle array[2] Werte in $pic3. Danach werde ich es serialisieren und in der Datenbank im Blob-Format speichern. Mit welcher Logik sollte ich das erreichen? Kann mir jemand helfen, indem ich dem Skript eine Logik gebe?

Vielen Dank im Voraus.

+0

Haben Sie eine feste Anzahl von Arrays? und in jedem Array hast du eine feste Anzahl von Elementen? – hassan

+0

ja diese sind behoben es wird nicht mehr als das und mindestens 2 Array wird dort sein – user7886262

Antwort

-1

Solange Ihr Code nicht wiedergegeben wird, werde ich das folgende Beispiel Angenommen:

$ar1 = [ 
    [1,2,3],[4,5,6],[7,8,9], 
]; 
$ar2 = [ 
    [1,2,3],[4,5,6],[7,8,9], 
]; 
$ar3 = [ 
    [1,2,3],[4,5,6],[7,8,9], 
]; 

foreach ($ar1 as $k => $ar) { 
    $pics[$k] = array($ar, $ar2[$k], $ar3[$k]); 
} 

print_r($pics); 

dies wird Ihren Array neu ordnen, müssen Sie den Code reproduzieren Ihre Bedürfnisse, anschauliches Beispiel passen: https://3v4l.org/lYQp6

+0

Dank @hassan, dass Logik perfekt funktioniert – user7886262

Verwandte Themen