<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: 1batu</title>
    <description>The latest articles on DEV Community by 1batu (@1batu).</description>
    <link>https://dev.to/1batu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F552938%2F6ef6b41b-c6b3-4e16-93f0-d6efb8820ed1.png</url>
      <title>DEV Community: 1batu</title>
      <link>https://dev.to/1batu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/1batu"/>
    <language>en</language>
    <item>
      <title>Value-based data assignment from json.</title>
      <dc:creator>1batu</dc:creator>
      <pubDate>Wed, 12 Oct 2022 06:19:29 +0000</pubDate>
      <link>https://dev.to/1batu/value-based-data-assignment-from-json-lcg</link>
      <guid>https://dev.to/1batu/value-based-data-assignment-from-json-lcg</guid>
      <description>&lt;p&gt;The scenario is as follows, the student takes the exam and according to the exam result, the system defines it to the training package. To do this, we define the score and package number in the database beforehand.&lt;/p&gt;

&lt;p&gt;The json structure we saved in the database is as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
{"score":"-35-39","package":"a1","price":"7500"},
{"score":"40-49","package":"a2","price":"6000"},
{"score":"50-59","package":"a3","price":"4500"},
{"score":"60-69","package":"a4","price":"3000"},
{"score":"70-79","package":"a5","price":"1500"},
{"score":"80-89","package":"a6","price":"free"},
{"score":"90-100","package":"a7","price":"free"}
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first thing we need is a variable where we will specify the student's score.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$point // Student score&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$points = json_decode(getSiteOptions('sbsJson'), true); 
// It is getting the above mentioned json data from my setting.
$point = 45; // Student score
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$data = [];
$points = json_decode(getSiteOptions('sbsJson'), true);
$point = 45;

foreach ($points as $a) {
        $parcala = explode('-', $a['score']);
        if ($parcala[0] !== "") {
            $parcala[0] = ((int) trim($parcala[0])) === 0 ? -1 : $parcala[0];
            if ($parcala[0] &amp;lt; $point &amp;amp;&amp;amp; $point &amp;lt;= $parcala[1]) 
            {
                $data = [
                    'sbs_package' =&amp;gt; $a['package'],
                    'sbs_price' =&amp;gt; $a['price']
                ];
            }
        } else {
            if ($point &amp;lt;= $parcala[1]) {
               $data = [
                    'sbs_package' =&amp;gt; $a['package'],
                    'sbs_price' =&amp;gt; $a['price']
                ];
            }
        }
}

return $data;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;It's working pretty well for me now, I'm waiting for your comments if we can fix it with a shorter code.. :)&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>laravel</category>
      <category>json</category>
      <category>programming</category>
      <category>php</category>
    </item>
  </channel>
</rss>
